wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.ClassName(className)) doesn't return any element

大兔子大兔子 提交于 2019-12-23 13:22:46

问题


I need to find IReadOnlyCollection<IWebElement> using WebDriverWait to make sure that elements had been rendered on page.

This is my code

 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
 return wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.ClassName("TextInput")));

This code failing on timeout. Meaning that could not find any elements on page with given class name. I added this line of code BEFORE my original code just to make sure that elements are present

 var allInputs1 = container.FindElements(By.ClassName("textInput"));

And that line returns elements as expected.

So my conclustion is that wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.ClassName("TextInput"))) doesn't work as expected since that couldn't find elements that are for sure present on page.

What is the best way to find array of elements using WebDriverWait?


回答1:


Your conclusion is wrong. With FindElements you just make sure that elements are present.

The API documentation for VisibilityOfAllElementsLocatedBy states:

An expectation for checking that all elements present on the web page that match the locator are visible. Visibility means that the elements are not only displayed but also have a height and width that is greater than 0.

And obviously present is not visible.

I think you should try ExpectedConditions.PresenceOfAllElementsLocatedBy



来源:https://stackoverflow.com/questions/39575177/wait-untilexpectedconditions-visibilityofallelementslocatedbyby-classnameclas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!