简体   繁体   中英

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. 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. 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. 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.

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).

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 . 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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