简体   繁体   English

使用Winium驱动程序和C#向下滚动

[英]Scroll down using winium driver with c#

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. 我也实现了Actions类。 But that even seem not working. 但这似乎不起作用。

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. 这样可行。

You can scroll to element using Winium.Elements this is available as a Nuget package https://github.com/2gis/Winium.Elements 您可以使用Winium.Elements滚动到元素,这可以通过Nuget包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 如果上述ele是组合框,则可以执行以下操作

 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM