当前位置: 首页 > 面试题库 >

Selenium-Firefox的MoveTargetOutOfBoundsException

林元明
2023-03-14
问题内容

我在 Firefox* Webdriver 上的move_to_element 函数遇到问题(Chrome,IE运行良好) *

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 //selenium-3.4.3

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

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)

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

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()

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



 类似资料:
  • 我是硒自动化的新手。我以管理员身份在系统中安装了Selenium IDE和Selenium RC(java-jar Selenium.jar)。另外,我使用的是Eclipse SDK版本3.7.1。编译代码时出现以下错误(运行为->TestNG测试) Selenium RC版本为2.42.2,firefox版本为23.0 错误: ==================================

  • 问题内容: 我正在尝试开始编写Selenium测试,并且我编写的第一个非常基本的测试因exception失败。 调试器说我需要下载geckodriver.exe并将其设置在我的PATH变量上,这已经完成,但仍然会出现相同的异常。当我对进行相同的操作时,效果很好。 同样,根据MDN,如果我使用的是Selenium 3.0或更高版本,则应默认启用它。我在Windows 10计算机上使用Selenium

  • 我对Selenium WebDriver没有什么问题。我使用的是最新的firefox版本(47.0),并与使用最新的Selenium-Server-standalone-2.53.0.jar绑定,但当我使用此版本时,使用了以下代码: 火狐打不开我收到消息说有问题,我可以去虫火狐。 当我尝试使用 Selenium-server-standalone-2.44.0 时.jar FireFox 窗口会打

  • 我试图从一个列表中自动设置多个表单,我打开到他们自己的选项卡。我可以在运行脚本之前准备页面的最简单的方法是将它们全部打开。我打算让selenium运行对表单的更改,然后我希望它在Ctrl+Tab下一个更改中运行。我将使用循环while来设置计数。我目前有它在HTML记录,如果我需要调整到java或我会很乐意这样做。 我试着录下来,但没有。

  • 对不起,我读了几篇文章,但没能找到解决方案。所以,我想做的是在WSL上使用硒和火狐。代码看起来像这样: 我得到的是以下(已知)错误: 这个日志显示: 1603805101772mozrunder::转轮INFO运行命令:"/usr/bin/Firefox""-木偶"-前景"-无远程"-配置文件"/tmp/rust_mozprofilehybl9w"错误:未指定DISPLAY环境变量16038053

  • 不应该driver.manage().timeouts().implicitlywait(15,timeunit.seconds);15秒后强制关闭selenium生成的Firefox浏览器?浏览器只是坐着说它在传输一个小时以上的数据。基本上只是挂着说它的转移... 我可以在Java中做些什么来解决这个问题吗? 问题:如何在N秒后强制关闭Selenium生成的Firefox窗口?