【问题标题】:ElementNotInteractableException using Selenium Python使用 Selenium Python 的 ElementNotInteractableException
【发布时间】:2021-04-27 03:07:55
【问题描述】:

我正在尝试在字段中输入一些文本,它是第一次工作,但之后,它显示此错误! ElementNotInteractableException我不知道为什么! 这是我的代码:

try:
    browser.execute_script("window.scrollBy(0,600)", "")
    WebDriverWait(browser, 60).until(EC.visibility_of_element_located((By.XPATH, path)))
    comment = browser.find_element_by_xpath("//XPATH")
    comment.send_keys(comments)

【问题讨论】:

标签: python selenium selenium-webdriver web-scraping webdriverwait


【解决方案1】:

要将字符序列发送到元素而不是visibility_of_element_located(),您需要为element_to_be_clickable() 诱导WebDriverWait,您可以使用以下任一Locator Strategy

try:
    browser.execute_script("window.scrollBy(0,600)", "")
    WebDriverWait(browser, 60).until(EC.element_to_be_clickable((By.XPATH, path)))
    comment = browser.find_element_by_xpath("//XPATH")
    comment.send_keys(comments)

注意:您必须添加以下导入:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 2018-11-23
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    相关资源
    最近更新 更多