Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find WebDriverWait class in OpenQA.Selenium (C#)

(Migrating from Java-Selenium to C#-Selenium)

When searching for explicit waits with Selenium and C# I find several posts with code that looks similar to the Java-Counterpart:

for example here:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5)); wait.Until(By.Id("login")); 

or here:

WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("locator"))); 

WebDriverWait are from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes

BUT:
When I try to code this myself in Visual Studio (getting Selenium package via NuGet), using WebDriverWait in my code will prompt the message:

The type or namespace name 'WebDriverWait' could not be found (are you missing a using directive or an assembly reference?)

Even though I am including the Selenium reference via

using OpenQA.Selenium; 

When looking up the documentation for WebDriverWait you will find, that there should be a namespace called

OpenQA.Selenium.Support.UI

But I cannot access it via "using" in my code.

Why does this happen? Where can I find the WebDriverWait class?

like image 905
drkthng Avatar asked Sep 18 '15 11:09

drkthng


People also ask

Is WebDriverWait a class in selenium?

WebDriverWait is a class. Q3. What is Fluent wait in selenium? The Fluent wait in selenium is to defined maximum time of wait for a condition and also frequency with which we want to check the condition before throwing an 'ElementNotVisibleException' exception.

What is WebDriverWait in selenium?

Selenium WebDriverWait is one of the Explicit waits. Explicit waits are confined to a particular web element. Explicit Wait is code you define to wait for a certain condition to occur before proceeding further in the code.

What is the exception thrown by WebDriver wait?

Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is in place, Implicit Wait stays in place for the entire duration for which the browser is open.


1 Answers

Luckily I sometimes read the comments to answers as well, so I stumbled across the solution within the highest ranked comment here:

WebDriverWait [is] from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes on NuGet

Thanks @Ved!

In Visual Studio this means, that you need to install TWO packages:

  • NuGet package "Selenium.WebDriver" AND ALSO
  • NuGet package "Selenium.Support"

Coming from Java with Maven, this is not trivial (at least to me ;-), because until now I just needed to include one and only one dependency to get "all of the good stuff" like this:

<dependency>     <groupId>org.seleniumhq.selenium</groupId>     <artifactId>selenium-java</artifactId>     <version>2.46.0</version> </dependency> 

* Posted this as a question including the answer because it cost me too much time and luck to stumble over the answer.

like image 197
drkthng Avatar answered Sep 29 '22 03:09

drkthng