Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
1 view
in DevOps and Agile by (19.4k points)

Is there any way in either Selenium 1.x or 2.x to scroll the browser window so that a particular element identified by an XPath is in view of the browser? There is a focus method in Selenium, but it does not seem to physically scroll the view in FireFox. Does anyone have any suggestions on how to do this?

The reason I need this is I'm testing the click of an element on the page. Unfortunately, the event doesn't seem to work unless the element is visible. I don't have control of the code that fires when the element is clicked, so I can't debug or make modifications to it, so, the easiest solution, scroll the item into view.

1 Answer

+1 vote
by (27.5k points)
edited by

Use the class org.openqa.selenium.interactions.Actions to move to an element.

WebElement element = driver.findElement(By.id("my-id"));

Actions actions = new Actions(driver);

actions.moveToElement(element);

actions.perform();

For more information please go through the following tutorial to get more info about selenium:

 

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...