I'm trying to write my own ExpectedConditions for Selenium but I don't know how to add a new one. Does anyone have an example? I can't find any tutorials for this online.
In my current case I want to wait until an element exists, is visible, is enabled AND doesn't have the attr "aria-disabled". I know this code doesn't work:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
return wait.Until<IWebElement>((d) =>
{
return ExpectedConditions.ElementExists(locator)
&& ExpectedConditions.ElementIsVisible
&& d.FindElement(locator).Enabled
&& !d.FindElement(locator).GetAttribute("aria-disabled")
}
EDIT: A little additional info: the problem I am running into is with jQuery tabs. I have a form on a disabled tab and it will start filling out fields on that tab before the tab becomes active.
Best Answer
An "expected condition" is nothing more than an anonymous method using a lambda expression. These have become a staple of .NET development since .NET 3.0, especially with the release of LINQ. Since the vast majority of .NET developers are comfortable with the C# lambda syntax, the WebDriver .NET bindings'
ExpectedConditions
implementation only has a few methods.Creating a wait like you're asking for would look something like this:
If you're not experienced with this construct, I would recommend becoming so. It is only likely to become more prevalent in future versions of .NET.