Scroll down using winium driver with c#

2.2k Views Asked by At

While selecting the location I’m able to click on the items which are visible. But I’m unable to select the other items which are not displayed in the dropdown list. When trying to select other location in dropdown list which is not visible in the drop-down, it is clicking somewhere else.

Below is the code snippet:

IWebElement ele = driver.FindElement(By.Id("cmbLocation"));
List<IWebElement> lis = ele.FindElements(By.ClassName("ListBoxItem"));
for(int i = 0; i< lis.size(); i++) {
    WebElement elem = lis.get(i).FindElement(By.name("LINWOOD"));
    if("LINWOOD".contains(elem.getText())) {
        lis.get(i).click();
        break;
    }
}

I have even tried just passing the index number as

lis.get(15).click();

I have implemented Actions class as well. But that even seem not working.

2

There are 2 best solutions below

0
On

I have also faced same issue. But, I didn't find solution. For temporary I have used one solution. But that is dirty fix.

If the drop down has the scroll down bar, click on that scroll down arrow till your element is visible, And then try to click on that element. That works.

0
On

You can scroll to element using Winium.Elements this is available as a Nuget package https://github.com/2gis/Winium.Elements

Once you have the above you can use it in your test like this

If the above ele is a combo box then you can do the below

 var comboBoxElement= ele.ToComboBox();

        comboBox.Expand();
        comboBox.ScrollTo("LINWOOD").Click();

If the above ele is a list box then you can do the below

 var listWebElement= ele .ToList();

     listWebElement.Scroll(By.Name("LINWOOD")).Click();