ElementNotInteractableException:消息:无法使用带有Selenium WebDriver的GeckoDriver Firefox将元素滚动到视图中 [英] ElementNotInteractableException: Message: Element could not be scrolled into view using GeckoDriver Firefox with Selenium WebDriver
问题描述
如何解决该错误:
selenium.common.exceptions.ElementNotInteractableException:消息:元素<>无法滚动到视图
通过Selenium使用Firefox时出现
错误?
该网站上的所有提示都没有帮助我.我尝试了所有可以找到的解决方案,包括通过WebDriverWait和JS.一种解决方案是:
selenium.common.exceptions.MoveTargetOutOfBoundsException:消息:(568,1215)超出了视口宽度(1283)和高度(699)的范围
我尝试调整浏览器窗口的大小,该窗口也不起作用.
我的代码:
webdriverDir ="/用户/管理员/桌面/MyVersion/geckodriver.exe"home_url ='https://appleid.apple.com/account/'浏览器= webdriver.Firefox(executable_path = webdriverDir)browser.get(home_url)browser.find_element_by_css_selector(验证码输入").click()
抛出窗口大小错误的解决方案:
actions = ActionChains(浏览器)等待= WebDriverWait(浏览器,10)元素= wait.until(EC.element_to_be_clickable((由CSS.SELECT_,验证码输入")))actions.move_to_element(element).perform()element.click()
顺便说一句,这些相同的代码在Chrome中可以完美运行.但这很明显.
要向< captcha-input>
字段发送字符序列,您必须诱导 WebDriverWait 作为 element_to_be_clickable()
,您可以使用以下任一
How can I fix the error:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <> could not be scrolled into view
error when working with Firefox via Selenium?
None of the tips from the site did not help me. I tried all the solutions I could find, including through WebDriverWait and JS. One of the solutions gave:
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (568, 1215) is out of bounds of viewport width (1283) and height (699)
I tried resizing the browser window, which also didn't work.
My code:
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()
A solution that throws a window size error:
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()
By the way, this same code works perfectly in Chrome. But it's obvious enough.
To send a character sequence to the <captcha-input>
field you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using
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")
Using
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")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
这篇关于ElementNotInteractableException:消息:无法使用带有Selenium WebDriver的GeckoDriver Firefox将元素滚动到视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!