AThis is a bit of a reimagining, but I think it will help.
Selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers
.
YouWith it, you can greatly simplify your code to just:
private void WaitFor(IWebDriver driver, By by, TimeSpan wait)
{
var smartWait = new WebDriverWait(driver, wait);
smartWait.Until(ExpectedConditions.ElementExists(by));
}
private void WaitFor(IWebDriver driver, By by, TimeSpan wait)
{
var smartWait = new WebDriverWait(driver, wait);
smartWait.Until(ExpectedConditions.ElementExists(by));
}
Usage:
WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));
WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));
This way, you are able to keep all of the parameters as open as you need them to be. The driver is always necessary. TheThe search criteria still let you use any available search patterns likepatterns—e.g., by CSS class or by id, andid—and the explicit timespan lets you understand the delay time at a glance.