Error CS0246: The type or namespace name 'WebDriverWait' could not be found?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Error CS0246: The type or namespace name 'WebDriverWait' could not be found?



I am new to creating tests in visual studio using selenium and C#. I have two files, one is search engine maing page and the other is a testing file. The files can be found here---https://www.automatetheplanet.com/page-object-pattern/



I always get this error;
Below are screenshots of the problem.



enter image description hereenter image description here



Error CS0246: The type or namespace name 'WebDriverWait' could not be found?



What am I doing wrong??



below is the following code-


using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

[TestClass]
public class SearchEngineTests
{
public IWebDriver Driver { get; set; }
public WebDriverWait Wait { get; set; }

[TestInitialize]
public void SetupTest()
{
this.Driver = new FirefoxDriver();
this.Wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(30));
}

[TestCleanup]
public void TeardownTest()
{
this.Driver.Quit();
}

[TestMethod]
public void SearchTextInSearchEngine_First()
{
SearchEngineMainPage searchEngineMainPage = new SearchEngineMainPage(this.Driver);
searchEngineMainPage.Navigate();
searchEngineMainPage.Search("Automate The Planet");
searchEngineMainPage.ValidateResultsCount("264,000 RESULTS");
}
}



This is the second file-


using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;

public class SearchEngineMainPage
{
private readonly IWebDriver driver;
private readonly string url = @"searchEngineUrl";

public SearchEngineMainPage(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}

[FindsBy(How = How.Id, Using = "sb_form_q")]
public IWebElement SearchBox { get; set; }

[FindsBy(How = How.Id, Using = "sb_form_go")]
public IWebElement GoButton { get; set; }

[FindsBy(How = How.Id, Using = "b_tween")]
public IWebElement ResultsCountDiv { get; set; }

public void Navigate()
{
this.driver.Navigate().GoToUrl(this.url);
}

public void Search(string textToType)
{
this.SearchBox.Clear();
this.SearchBox.SendKeys(textToType);
this.GoButton.Click();
}

public void ValidateResultsCount(string expectedCount)
{
Assert.IsTrue(this.ResultsCountDiv.Text.Contains(expectedCount), "The results DIV doesn't contains the specified text.");
}
}





possible duplicate of stackoverflow.com/questions/32651528/…
– cruisepandey
8 hours ago




2 Answers
2



Think you are missing namespace using OpenQA.Selenium.Support.UI;


using OpenQA.Selenium.Support.UI;



WebDriverWait is available in the Selenium.Support package. So, Please import the below package in SearchEngineTests Test class.


WebDriverWait


SearchEngineTests


using OpenQA.Selenium.Support.UI;



TimeSpan is available in the default System package.so, please import the below package as well


TimeSpan


System


using System



Regarding to add the required namespace, If you are seeing any red color underlined code in your program, then move the cursor towards that particular field. It will give the suggestion to add the relevant namespace





Error CS1729: 'SearchEngineMainPage' does not contain a constructor that takes 1 arguments (CS1729) (testingProgram)
– Novice_29
4 hours ago





Error CS0103: The name 'TimeSpan' does not exist in the current context (CS0103) (testingProgram)
– Novice_29
4 hours ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived