【问题标题】:Selenium error namely 'selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable'Selenium 错误即“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”
【发布时间】:2020-11-05 05:51:20
【问题描述】:

我在尝试在 whatsapp 中自动发送消息时收到此错误。这是源代码。

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome('C:/Users/HP/Downloads/chromedriver/chromedriver.exe')
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)
target = 'Name of friend or group'
string = "Hello!! sent using selenium.."
x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//div[@class="input"][@dir="auto"][@data-tab="1"]'
input_box = wait.until(EC.presence_of_element_located((By.XPATH, inp_xpath)))
for i in range(100):
    input_box.send_keys(string + Keys.ENTER)
    time.sleep(1)

【问题讨论】:

  • 请添加完整的异常堆栈跟踪。这有助于我们跟踪错误。

标签: python python-3.x selenium selenium-webdriver chrome-web-driver


【解决方案1】:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 这个错误意味着当你试图点击一个元素时它是不可交互的。因此,例如,如果您首先放置了一个按钮列表,您应该打开此列表,然后单击该按钮。可能是当您执行此代码时 group_title.click() 您的 group_title 无法交互。

【讨论】:

    【解决方案2】:

    当您尝试与之交互的元素不在当前农场的主流中时,就会发生这种情况 你应该考虑改变框架:

    driver.switch_to.frame(input_box)
    

    完成后

    driver.switch_to.default_content()
    

    【讨论】:

    • 这里的交互是send_keys所以在此之前切换
    猜你喜欢
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 2019-12-20
    相关资源
    最近更新 更多