Selenium-Firefox的MoveTargetOutOfBoundsException [英] Selenium - MoveTargetOutOfBoundsException with Firefox

查看:484
本文介绍了Selenium-Firefox的MoveTargetOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Firefox Webdriver上使用功能 move_to_element 遇到了问题(Chrome浏览器,IE很好用)

I'v got problem with function move_to_element on Firefox Webdriver (Chrome, IE works well)

driver = webdriver.Firefox()
driver.get("https://stackoverflow.com")
time.sleep(5)
source_element = driver.find_element_by_xpath('//*[@id="footer"]/div/ul/li[1]/a')
ActionChains(driver).move_to_element(source_element).perform()

我正在使用以下版本:geckodriver-0.17.0//Firefox-54.0//硒-3.4.3

I am working with these versions: geckodriver - 0.17.0 // Firefox - 54.0 // selenium - 3.4.3

运行此脚本后,在输出上显示:

After running this script, on output shows:

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (134.96666717529297, 8682.183013916016) is out of bounds of viewport width (1268) and height (854) 

推荐答案

此错误...

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (134.96666717529297, 8682.183013916016) is out of bounds of Viewport width (1268) and height (854)

...表示您要查找的元素不在视口.我们需要向下滚动以将元素放入视口中.这是工作代码:

...implies that the element you are looking for is not within the Viewport. We need to scroll down to bring the element within the Viewport. Here is the working code:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get("https://stackoverflow.com")
last_height = driver.execute_script("return document.body.scrollHeight")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
source_element = driver.find_element_by_xpath('//*[@id="footer"]/div/ul/li[1]/a')
ActionChains(driver).move_to_element(source_element).perform()

让我知道这是否回答了您的问题.

Let me know if this Answers your Question.

这篇关于Selenium-Firefox的MoveTargetOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆