selenium send_keys()消息:元素不可交互

时间:2020-07-02 17:58:39

标签: 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)

请帮助

1 个答案:

答案 0 :(得分:0)

出现错误的原因似乎是因为您使用的是具有Div元素的SendKeys方法,而不是输入或文本区域。

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