使用此 xpath 向各种 whatsApp 用户发送自动消息以单击发送开始不起作用

send automated messages to various whatsApp users using this xpath to click send started not to work

我曾经使用此 xpath 代码向各种 whatsApp 用户发送自动消息以单击发送按钮。 navegador.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]').send_keys(Keys.SEND)

它最近停止工作,说找不到 xpath。 selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="main"]/footer/div[1]/div[2]/div/div[2]/button"} (Session info: chrome=91.0.4472.124)

我已经尝试更新 xpath,因为它接缝已更改为: //*[@id="main"]/footer/div[1]/div[2]/div/div[2]/button 但我仍然收到相同的错误消息。

我还看到一个线程暗示可能没有为当前页面设置驱动程序。如果是这样,我该如何解决? selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=81.0.4044.138)

我错过了什么?

提前感谢您对此问题的任何帮助。

可能是您的定位器不正确。
此外,在将文本插入消息文本区域后,发送元素按钮会出现短暂的延迟。
试试这个:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

wait.until(EC.visibility_of_element_located((By.XPATH, '//span[@data-testid="send"]'))).click()