Home > Software design >  The name 'ExpectedConditions' does not exist in the current context
The name 'ExpectedConditions' does not exist in the current context

Time:06-07

I have to perform an action after an element is visible in the UI for this I'm using the below code but ExpectedConditions class is throwing an error saying The name 'ExpectedConditions' does not exist in the current context. Please suggest.

public void WaitForElementLoad(By by, int timeoutInSeconds)
{
    if (timeoutInSeconds > 0)
    {
        WebDriverWait wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeoutInSeconds));
        wait.Until(ExpectedConditions.ElementIsVisible(by));
    }
}

Error CS0234 The type or namespace name 'ExpectedConditions' does not exist in the namespace 'OpenQA.Selenium.Support.UI' (are you missing an assembly reference?)

CodePudding user response:

The below will solve your problem

Make sure you've installed both the Selenium.Webdriver and Selenium.Support NuGet packages for your project. You'll need the Selenium.Support package to use ExpectedCondition

OR

Resolve this way:

1: Using nuget, search for DotNetSeleniumExtras.WaitHelpers,

2: Import that namespace into your class.

using SeleniumExtras.WaitHelpers

3: Then example of code code:

 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("element ID")));
  • Related