在Visual Studio 2012中使用Selenium库编写的C#代码中出错
从以下帖子获得帮助:- 当我写上述代码时,我得到以下错误:- 1.驱动程序变量中存在错误。错误消息“驱动程序是一个字段,但用作类型。 2.在大括号上导航(),获取无效标记。 3.gotour->方法必须具有返回类型在Visual Studio 2012中使用Selenium库编写的C#代码中出错,c#,.net,selenium,C#,.net,Selenium,从以下帖子获得帮助:- 当我写上述代码时,我得到以下错误:- 1.驱动程序变量中存在错误。错误消息“驱动程序是一个字段,但用作类型。 2.在大括号上导航(),获取无效标记。 3.gotour->方法必须具有返回类型 using System.Text; using System.Threading.Tasks; using System.Xml.XPath; using OpenQA.Selenium; using OpenQA.Selenium.Support; using OpenQA.Se
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();
}
}
我已添加了我项目中的所有库,请帮助查找错误原因。您发布的代码不在方法中。您需要使用类似于以下内容的代码:
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();
}
}
}
@乔治·贝利(George Bailey)-创建了新问题,并按照建议链接到旧问题。