I have faced a weird situation, where on the page in Serenity I have to scroll to the element:
withAction().moveToElement(webElement).perform();
This error message...
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:
(377.375, 958.3999938964844) is out of bounds of viewport width (1268) and height (943)
...implies that Selenium was unable to focus on the desired element as the element was out of bounds of the viewport.
Your main issue is the WebElement identified as webElement is out of Viewport so Selenium can't move the focus on the desired element through moveToElement()
method.
A simple solution would be to use the executeScript()
method to bring the desired element within the viewport and then invoke moveToElement()
method as follows:
WebElement myElement = driver.findElement(By.xpath("xpath_of_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", myElement);
withAction().moveToElement(webElement).perform();