【问题标题】:ElementNotInteractableException: Message: Element could not be scrolled into view using GeckoDriver Firefox with Selenium WebDriverElementNotInteractableException:消息:使用带有 Selenium WebDriver 的 GeckoDriver Firefox 无法将元素滚动到视图中
【发布时间】:2020-01-08 04:46:15
【问题描述】:

我该如何解决这个错误:

selenium.common.exceptions.ElementNotInteractableException: Message: Element <> could not be scrolled into view

通过 Selenium 使用 Firefox 时出错?

网站上的所有提示都没有帮助我。我尝试了所有我能找到的解决方案,包括通过 WebDriverWait 和 JS。其中一种解决方案给出了:

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (568, 1215) is out of bounds of viewport width (1283) and height (699)

我尝试调整浏览器窗口的大小,但也没有用。

我的代码:

webdriverDir = "/Users/Admin/Desktop/MyVersion/geckodriver.exe"
home_url = 'https://appleid.apple.com/account/'
browser = webdriver.Firefox(executable_path=webdriverDir)
browser.get(home_url)
browser.find_element_by_css_selector("captcha-input").click()

引发窗口大小错误的解决方案:

actions = ActionChains(browser)
wait = WebDriverWait(browser, 10)
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "captcha-input")))
actions.move_to_element(element).perform()
element.click()

顺便说一句,同样的代码在 Chrome 中也能完美运行。但这已经足够明显了。

【问题讨论】:

    标签: python-3.x selenium-webdriver xpath css-selectors webdriverwait


    【解决方案1】:

    要将字符序列发送到&lt;captcha-input&gt; 字段,您必须为element_to_be_clickable() 诱导WebDriverWait,您可以使用以下Locator Strategies 之一:

    • 使用CSS_SELECTOR

      driver.get('https://appleid.apple.com/account#!&page=create')
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.captcha-input input.generic-input-field"))).send_keys("JohnTit")
      
    • 使用XPATH

      driver.get('https://appleid.apple.com/account#!&page=create')
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//captcha-input//input[@class='generic-input-field   form-textbox form-textbox-text  ']"))).send_keys("JohnTit")
      
    • 注意:您必须添加以下导入:

      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
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      相关资源
      最近更新 更多