我在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:消息:(134.96666717529297,8682.183013916016)超出视口宽度(1268)和高度(854)的范围.您要查找的元素不在Viewport之内.我们需要向下滚动以将元素带入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()
如果这回答你的问题,请告诉我.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。