ElementNotInteractableException:消息:使用带有Selenium WebDriver的GeckoDriver Firefox无法将元素滚动到视图中

问题描述 投票:0回答:1

如何解决错误:

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个回答
0
投票
字符序列,您必须为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

  • 浏览器快照:
  • AppleID_CaptchaInput
  • © www.soinside.com 2019 - 2024. All rights reserved.