Selenium - MoveTargetOutOfBoundsException with Firefox

I have a problem with move_to_element function 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()

      

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

After running this script, the output displays:

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

      

+3


source to share


2 answers


Here is the answer to your question:

The error you are seeing says that everything is like selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (134.96666717529297, 8682.183013916016) is out of bounds of Viewport width (1268) and height (854)

. The item you are looking for is not in the Viewport . We need to scroll down to bring the item to the Viewport . Here's 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.

+2


source


Try setting the window size for the driver BEFORE the driver driver.get ()



driver.set_window_size(1024, 768) #(1920, 1080) #(4096, 3112)

      

0


source







All Articles