首页 > 解决方案 > 不推荐使用 DesiredCapabilities,我将如何在 selenium webdriver C# 中使用 SetCapability?

问题描述

不推荐使用 DesiredCapabilities,我将如何在 selenium webdriver C# 中使用 SetCapability?

我可以这样使用吗?

capacidades = new ChromeOptions();
capacidades.AddAdditionalCapability(@"browserName", @"chrome");

标签: c#seleniumselenium-webdriverautomated-tests

解决方案


在 JimEvans 的答案中添加一个简单的示例。

禁用 chrome 信息栏的简单示例:

private IWebDriver GetChromeDriver()
{
    var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

    //Disable chrome info bar in order to prevent "Chrome is being run by automation software."
    var chromeOption = new ChromeOptions();
    chromeOption.AddArguments("disable-infobars");

    return new ChromeDriver(outPutDirectory, chromeOption);
}

推荐阅读