use of org.openqa.selenium.WrapsDriver in project acceptance-test-harness by jenkinsci.
the class Scroller method scrollIntoView.
/**
* The framework is expected to take care of the correct scrolling. When you are tempted to scroll from PageObjects
* or tests, there is likely a framework problem to be fixed.
*/
public void scrollIntoView(WebElement e, WebDriver driver) {
if (driver instanceof HtmlUnitDriver || (driver instanceof WrapsDriver && ((WrapsDriver) driver).getWrappedDriver() instanceof HtmlUnitDriver)) {
return;
}
WebElement element = e;
if (Objects.equals(element.getTagName(), "option")) {
// scroll select into view not option
element = e.findElement(By.xpath(".."));
}
final int eYCoord = element.getLocation().getY();
final int eXCoord = element.getLocation().getX();
final String id = element.getAttribute("id");
final JavascriptExecutor executor = (JavascriptExecutor) driver;
// Wait until web element is successfully scrolled.
try {
new Wait<>(Boolean.TRUE).withTimeout(5, // Wall-clock time
TimeUnit.SECONDS).until(() -> (Boolean) executor.executeScript(scrollJs, eYCoord, eXCoord, id));
} catch (TimeoutException ex) {
// Scrolling failed, but sometimes the element to click is already visible, let the test continue and eventually fail later
// This log message should be sufficient to diagnose the issue
LOGGER.log(Level.WARNING, "Scrolling failed, letting the test to continue anyways, but \"Element is not clickable\" error will likely be thrown", ex);
}
}
Aggregations