How to perform a scroll in a drop down list to hidden element?

Emna Ayadi picture Emna Ayadi · Jun 6, 2016 · Viewed 17.9k times · Source

How to perform a scroll in a drop down list with that format with selenium, appium ? I'm using tag name to identify elements, <md-option .../> are the items in the drop down list. enter image description here

Here is my html code :

enter image description here

Answer

Emna Ayadi picture Emna Ayadi · Jun 6, 2016

I have solved it by this way :

// Create instance of Javascript executor
JavascriptExecutor je = (JavascriptExecutor) driver;
//Identify the WebElement which will appear after scrolling down
WebElement element = driver.findElement(By.tagName("...."));
// now execute query which actually will scroll until that element is not appeared on page.
je.executeScript("arguments[0].scrollIntoView(true);",element);