Skip to main content
Minor updates to wording and punctuation to aid in readability. (Previous suggestions conflicted with a similar concurrent edit; reapplying difference.)
Source Link

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.

A bit of a reimagining but I think will help.

Selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers.

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));
}

Usage:

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

This way you keep all parameters as open as you need them to be. The driver is always necessary. The search criteria still let you use any available search patterns like by CSS or by id, and the explicit timespan lets you understand the delay time at a glance.

This is a bit of a reimagining, but I think it will help.

Selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers.

With 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));
}

Usage:

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. The search criteria still let you use any available search patterns—e.g., by CSS class or by id—and the explicit timespan lets you understand the delay time at a glance.

added 6 characters in body
Source Link
mdfst13
  • 21.7k
  • 6
  • 33
  • 68

aA bit of a reimagining but I think will help.

seleniumSelenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers.

youYou 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));
}

usageUsage:

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

This way you keep all parameters as open as you need them to be. The driver is always necessary, the. The search criteria still letslet you use any available search patterspatterns like by cssCSS or by id, and the explicit timespan lets you at a glance understand the delay time at a glance.

a bit of a reimagining but I think will help

selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers

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));
}

usage

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

This way you keep all parameters as open as you need them to be. The driver is always necessary, the search criteria still lets you use any available search patters like by css or by id, and the explicit timespan lets you at a glance understand the delay time

A bit of a reimagining but I think will help.

Selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers.

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));
}

Usage:

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

This way you keep all parameters as open as you need them to be. The driver is always necessary. The search criteria still let you use any available search patterns like by CSS or by id, and the explicit timespan lets you understand the delay time at a glance.

further elaboration
Source Link

a bit of a reimagining but I think will help

selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers

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));
}

usage

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

thisThis way you keep all parameters as open as you need them to be. The driver is always necessary, the search criteria still lets you use any available search patters like by css or by id, and the explicit timespan lets you at a glance understand the delay time

a bit of a reimagining but I think will help

selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers

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));
}

usage

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

this way you keep all parameters as open as you need them to be.

a bit of a reimagining but I think will help

selenium actually has a smart wait helper package called DotNetSeleniumExtras.WaitHelpers

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));
}

usage

WaitFor(driver, By.XPath(".//*[@id='content']"), TimeSpan.FromSeconds(10));

This way you keep all parameters as open as you need them to be. The driver is always necessary, the search criteria still lets you use any available search patters like by css or by id, and the explicit timespan lets you at a glance understand the delay time

Source Link
Loading