我在代码中收到一条错误消息,指出Chrome的DesiredCapabilities已过时

时间:2018-10-05 10:48:36

标签: c# selenium

在我的部分代码中,我收到一条错误消息,指出该代码无法访问。

在第二部分中,我收到一条错误消息,表明DesiredCapabilitie已过时。

我该如何解决这个问题?

我的代码如下:

public void CreateWebDriver()         {

        if (false)
        {
            var pathToDriver = ConfigurationManager.AppSettings["PathToChromeDriverLocal"];

            var chromeOptions = new ChromeOptions();
            chromeOptions.AddArguments("--disable-extensions");
            WebDriver = new ChromeDriver(pathToDriver, chromeOptions);
        }
        else if (true)
        {
            var pathToDriver = ConfigurationManager.AppSettings["PathToChromeDriverRemote"];

            DesiredCapabilities chromeCapabilities = DesiredCapabilities.Chrome();
            chromeCapabilities.SetCapability("chrome.binary", @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
            WebDriver = new RemoteWebDriver(new Uri(pathToDriver), chromeCapabilities);
        }
    }

1 个答案:

答案 0 :(得分:0)

if(false){
// code unreachable because condition is always false
}

// You have to try like this
int a=5,b=10
if(a>b){ // do something 
}
else if(a=b){ // do something 
} 
else { // do something 
}