6

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

Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77

2 Answers2

6

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);
Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
  • What if I don't know what the element is and I just want the combo box to scroll down to the end? Can I do that? – Harvey Lin Jan 05 '18 at 22:23
  • 1
    WebElement element = driver.findElement(By.tagName("....")); returns no results because the element has not yet appeared on the page, it will appear only after scrolling the dropdown scrollbar.. – hipokito Feb 24 '21 at 17:11
2

Try following code.

browser.executeScript('window.scrollTo(0,0);').then(function () {
    page.saveButton.click();
})

Hope this helps. :)

Manuli
  • 1,203
  • 4
  • 20
  • 43