简体   繁体   English

具有Kendo UI的C#Selenium Web驱动程序:如何完全填充kendo下拉列表

[英]C# Selenium Web Driver with Kendo UI: How to wait for the kendo drop down list is fully populated

When a Kendo Drop Down list contains many values, it does takes times (5 seconds +) to load all values. 当Kendo下拉列表包含许多值时,加载所有值的确花费时间(5秒以上)。 When loading the values there is a spin indicator (busy icon) on the drop down element to indicates values are being populated. 加载值时,下拉元素上有一个旋转指示器(忙碌图标),用于指示正​​在填充值。

在此处输入图片说明

when all values are populated the user can then click on the drop down to select a value. 当所有值都填写完毕后,用户可以单击下拉列表以选择一个值。

Currently I am using Thread.Sleep(10000) to force Selenium Web Driver to wait until all values are populated. 目前,我正在使用Thread.Sleep(10000)强制Selenium Web Driver等待,直到填充所有值。 I know using Tread.Sleep is a BAD practice I can't seem to find a better solution as I cannot get hold of the indicator element. 我知道使用Tread.Sleep是一种不好的做法,因为我无法掌握指标元素,因此似乎找不到更好的解决方案。 I also got a Wait On a Page to be ready and does not seem to do anything, it works on normal pages BUT not Kendo UI. 我还准备了“等待页面”,但似乎什么也没做,它可以在普通页面上工作,但不能在Kendo UI上工作。

As anyone came across this issue? 当有人遇到这个问题?

Thanks 谢谢

You should do an explicit wait (after clicking to open the list), and use the ExpectedCondition either that the UI element of the list is present, or that it is 'Visible', depending on which works for you (it depends on how the dropdown list is implemented). 您应该进行明确的等待(单击以打开列表后),并使用ExpectedCondition来确定列表的UI元素是否存在或“可见”,具体取决于哪个对您有效(取决于如何下拉列表已实现)。

Instead of something like this: 代替这样的事情:

var element = driver.FindElement(By.ID("foo"))

you would do: 你会做:

var element = new WebDriverWait(driver, TimeSpan.FromSeconds(10))
                     .Until(ExpectedConditions.presenceOfElementLocated(By.ID("foo"));

There You can obviously use different types of By . 在那里,您显然可以使用不同类型的By There is also ExpectedConditions.visibilityOfElementLocated and various others, see https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java 还存在ExpectedConditions.visibilityOfElementLocated和其他各种信息,请参见https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java

This is called an explicit wait because you explicitly set what condition is needed for that element. 这称为显式等待,因为您显式设置了该元素所需的条件。 If it detects that the condition if met during that time, it will immediately carry on. 如果在此期间检测到满足条件,它将立即继续进行。 If it times out, an exception will be thrown. 如果超时,将引发异常。

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

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