Scrolling using selenium webdriver in Java
•
Java
I'm using selenium webdriver to automate browser testing My browser header is floating and always exists regardless of browser scrolling
Therefore, when I click on some elements below the currently visible area of the browser, I try to scroll the elements into the view and click them
However, due to automatic scrolling, the elements scroll after the floating title, and when you do anything on them, the elements in the header are clicked
Is there any way to limit the default scrolling of webdriver?
Solution
Locatable hoverItem = (Locatable) driver.findElement(By.xpath("//li[text()='Reklama w Google']"));
Locatable hoverItem = (Locatable) driver.findElement(By.xpath("//li[text()='Reklama w Google']")); int y = hoverItem.getCoordinates().getLocationOnScreen().getY(); ((JavascriptExecutor)driver).executeScript("window.scrollBy(0,"+y+");");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码