Wednesday, July 11, 2012

Selenium 2: How to scroll to element using WebDriver


Check new series of the articles. Review and user experience on test management systems. Functionality and usability.
-------------------

Some actions you take with WebElement's may fail due to those elements are not currently in the browser's visible area. So to make them able to interact you should first scroll vertically (or sometimes even horizontally :) ). However WebDriver does not provide explicit scrolling functionality.
Nevertheless you can bring the required element to the viewport. To to that just do the following

((Locatable)element).getLocationOnScreenOnceScrolledIntoView();

Where element is that WebElement you're going to interact with.