Reputation: 33
Got help from below post:-How to set up Selenium to work with Visual Studio .NET using C#?
When I am writing above code I am getting below error:- 1. Error in driver variable. Error message "driver is a field but used like a type. 2. Navigate() on braces getting Invalid token. 3. GoToUrl -> Method must have a return type.
using System.Text;
using System.Threading.Tasks;
using System.Xml.XPath;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
namespace BMCPerceiver
{
public class Class1
{
// Step b - Initiating webdriver
IWebDriver driver = new FirefoxDriver();
//Step c : Making driver to navigate
driver.Navigate().GoToUrl("http://docs.seleniumhq.org/");
//Step d
IWebElement myLink = driver.FindElement(By.LinkText("Download"));
myLink.Click();
//Step e
driver.Quit();
}
}
I have added all libraried on my Project, Please help in finding out the cause of the error's
Upvotes: 0
Views: 829
Reputation: 27496
Your code as published is not inside a method. You'll need to use code similar to the following:
using System.Text;
using System.Threading.Tasks;
using System.Xml.XPath;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
namespace BMCPerceiver
{
public class Class1
{
public void Method1()
{
// Step b - Initiating webdriver
IWebDriver driver = new FirefoxDriver();
//Step c : Making driver to navigate
driver.Navigate().GoToUrl("http://docs.seleniumhq.org/");
//Step d
IWebElement myLink = driver.FindElement(By.LinkText("Download"));
myLink.Click();
//Step e
driver.Quit();
}
}
}
Upvotes: 1