I'm using Python 3.9 with the latest Selenium and have this code, which runs fine on my Mac, Chrome driver 101 headless instance of my script ...
element = self.driver.find_element(By.CSS_SELECTOR, "body")
actions = ActionChains(self.driver)
actions.move_to_element_with_offset(element, 0, 0).perform()
However, when I run this same code on my CentOS 7 instance, with chromedriver 99 (latest available), I get this error
> raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds
E (Session info: headless chrome=99.0.4844.84)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py:242: MoveTargetOutOfBoundsException
Any thoughts on what this means or what additional configurations I may need to make on my CentOS 7 setup? Happy to rewrite the code as long as it runs on both environments.
From Selenium documentation for MoveTargetOutOfBoundsException:
Indicates that the target provided to the actions move() method is invalid - outside of the size of the window.
From Actions class documentation:
moveByOffset(int xOffset, int yOffset)
Moves the mouse from its current position (or 0,0) by the given offset.
This issue looks odd for me as we are talking about the body element, and somehow it is not in the visible part of your screeen, you can try:
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
document.body.scrollHeight
window.innerHeight
References:
How to get the browser viewport dimensions?
https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.openqa.selenium.interactions.MoveTargetOutOfBoundsException
Selenium - MoveTargetOutOfBoundsException with Firefox
https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#getLocation()