eastwater
eastwater

Reputation: 5572

ExpectedConditions.presenceOfAllElementsLocatedBy how many?

ExpectedConditions.presenceOfAllElementsLocatedBy(locator)

How webDriver knows how many elements are located for presence by the locator?

Upvotes: 1

Views: 439

Answers (3)

Key Point: Find all elements within the current page using the given By mechanism to locate elements within a document with the help of locator value.

When implicitly waiting, this method will return as soon as there are more than 0 items in the found collection, or will return an empty list if the timeout is reached.

Upvotes: 1

JeffC
JeffC

Reputation: 25611

If you look at the code, it just grabs all elements that match the provided locator. The only thing it catches is StaleElementReferenceException. The full code is below with a link to the source.

/// <summary>
/// An expectation for checking that all elements present on the web page that
/// match the locator.
/// </summary>
/// <param name="locator">The locator used to find the element.</param>
/// <returns>The list of <see cref="IWebElement"/> once it is located.</returns>
public static Func<IWebDriver, ReadOnlyCollection<IWebElement>> PresenceOfAllElementsLocatedBy(By locator)
{
    return (driver) =>
    {
        try
        {
            var elements = driver.FindElements(locator);
            return elements.Any() ? elements : null;
        }
        catch (StaleElementReferenceException)
        {
            return null;
        }
    };
}

https://github.com/DotNetSeleniumTools/DotNetSeleniumExtras/blob/master/src/WaitHelpers/ExpectedConditions.cs

Upvotes: 1

supputuri
supputuri

Reputation: 14135

presenceOfAllElementsLocatedBy will check of presence of atleast one element then it will return all the elements that matches the provided locator.

Here is the official documentation from method implementation.

An expectation for checking that there is at least one element present on a web page.

locator is used to find the element

returns the list of WebElements once they are located

Here is the official link to the java doc. https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#presenceOfAllElementsLocatedBy-org.openqa.selenium.By-

Upvotes: 0

Related Questions