Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Visual Studio 2012中使用Selenium库编写的C#代码中出错_C#_.net_Selenium - Fatal编程技术网

在Visual Studio 2012中使用Selenium库编写的C#代码中出错

在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

从以下帖子获得帮助:-

当我写上述代码时,我得到以下错误:- 1.驱动程序变量中存在错误。错误消息“驱动程序是一个字段,但用作类型。 2.在大括号上导航(),获取无效标记。 3.gotour->方法必须具有返回类型

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)-创建了新问题,并按照建议链接到旧问题。