Search code examples
c#seleniumwebdriverwait

ExpectedCondition method attributeContains for C#


I was trying to use "attributeContains" method but I don't have it avaible when using C#. https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#attributeContains-org.openqa.selenium.WebElement-java.lang.String-java.lang.String-

Any workaround?


Solution

  • You can always create your custom Expected Condition:

    public void AttributeContains(By locator, String attribute, String value, int secondsToWait = 30)
    {
       new WebDriverWait(driver, new TimeSpan(0, 0, secondsToWait))
          .Until(d => d.FindElement(locator).GetAttribute(attribute) == value);
    }
    

    Forgive my rusty C# skills in case there are syntax errors.