使用 python3 和 selenium with chromium 发送消息。
在 ARM64 上运行,使用 fedora33
下面的代码工作了一段时间,但在 7 月的第 2 周停止工作
我没有更改任何软件或程序代码。
以下是我遇到的错误,您能帮忙解决吗,谢谢。
错误消息:元素不可交互
( session 信息:chrome=91.0.4472.101)
Blow 是我的代码片段(之前完美无瑕):
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("user-data-dir=" + "cookies")
display = Display(visible=0, size=(1360, 768))
display.start()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get('https://web.whatsapp.com')
sleep(20)
driver.find_element_by_xpath('//*[@title = "{}"]'.format(wa_contact)).click()
sleep(10)
wa_msg = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
sleep(20)
# Put the message in one-block
for i in wa_message_li:
wa_msg.send_keys(i + Keys.SHIFT + Keys.RETURN)
wa_msg.send_keys(Keys.ENTER)
sleep(15)
driver.quit()
display.stop()
Tried options like increasing the sleep time and class name, etc. (as suggested in other solutions on similar topic)
最佳答案
终于解决了这个错误。
它在 xpath 中,有以下更新
从:
driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
至:
driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[1]')
注意:最后的“div[2]”更新为“div[1]”
关于python - Selenium WhatsApp 异常 "element not interactable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68438964/