2

I am waiting for an element Attribute aria-sort to equal "descending".

Currently using C# Selenium webdriver. How do I conduct this? I do not see AttributeContains in Visual Studio.

How to wait for a element to contain a specific attribute through Selenium and WebDriverWait?

boolean status = new WebDriverWait(driver, 20).until(ExpectedConditions.attributeContains(By.xpath("//div[@class='model-holder']/span[contains(.,'200K')]"), "class", "model-ready"));
1

2 Answers 2

1

Additionally to the way presented in the post you have mentioned in your question you can also do the following:
Let's say that element can be uniquely located by the following XPath //tag[@class='theClass']
So when this element will have aria-sort attribute equals to descending, then this element can be located by this XPath: //tag[@class='theClass' and(@aria-sort='descending')]
So you can simply use regular ElementExists ExpectedConditions as following:

boolean status = new WebDriverWait(driver, 20).until(ExpectedConditions.ElementExists(By.xpath("//tag[@class='theClass' and(@aria-sort='descending')]"));

However this approach is not really good since it is not general enough, so it's much better to create custom ExpectedConditions according to the element attribute as described here

Sign up to request clarification or add additional context in comments.

Comments

0

I have Written an extension method in C# Selenium , this will help to wait until a particular element / attribute is visible.

Call This method like : WaitUntilElementIsVisible(driver, By.Id("DemoId")); // example

public static bool WaitUntilElementIsVisible(IWebDriver browser, By by)
{
            int attemptToFindElement = 0;
            bool elementFound = false;
            IWebElement elementIdentifier = null;
            do
            {
                attemptToFindElement++;
                try
                {
                    elementIdentifier = browser.FindWebElement(by);
                    elementFound = (elementIdentifier.Displayed && elementIdentifier.Enabled) ? true : false;
                }
                catch (Exception)
                {
                    elementFound = false;
                }

            }
            while (elementFound == false && attemptToFindElement < 100);

            return elementFound;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.