python - Selenium send_keys() 消息 : element not interactable

标签 python selenium whatsapp

from selenium import webdriver
import time
import os, time

driver = webdriver.Chrome(executable_path=r"C:\Users\carlo\OneDrive\Escritorio\chromedriver.exe")
driver.get("https://web.whatsapp.com/")

time.sleep(10)

name = 'me'

user = driver.find_elements_by_xpath('//span[@title = "{}"]'.format(name))[0]
user.click()

msj_box = driver.find_element_by_xpath('//div[@class="_2FbwG"]')
msj_box.send_keys('la caja')
msj_box = driver.find_element_by_xpath('//button[@class="_1U1xa"]')
msj_box.click()

运行以下行时出现问题

msj_box.send_keys('la caja')

输出是这样的

 File "c:/Users/carlo/OneDrive/Escritorio/wp3.py", line 23, in <module>
    msj_box.send_keys('la caja')
  File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute 
    return self._parent.execute(command, params)
  File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute   
    self.error_handler.check_response(response)
  File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=83.0.4103.116)

请帮忙

最佳答案

您收到错误的原因似乎是因为您将 SendKeys 方法与 Div 元素一起使用,而不是用于输入或文本区域。

msj_box = driver.find_element_by_xpath('//div[@class="_2FbwG"]')

关于python - Selenium send_keys() 消息 : element not interactable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62702419/

相关文章:

python - 单击带有 selenium 和 python 的 href 按钮?

php - 如何检索旧的 Whatsapp 个人资料图片?

ios - UIActivityViewController 错误 : Failed to determine whether URL is managed by a file provider

python - 如何从javascript代码中提取字符串?

java - 在 python 中使用 subprocess.Popen 运行 java 主类

python - 如何使用 withColumn 对具有 NA 值的变量求和

selenium - Chromedriver --screenshot 在 headless (headless)模式下不起作用?

python - 使用 HDFStore 文件的线程和异常安全方式

java - Selenium 在进入下一页之前需要 sleep

javascript - 使用 html 或 jquery 或 javascript 在 Whatsapp 中发送图片