【问题标题】:With DesiredCapabilities deprecated, how will I use SetCapability in selenium webdriver C #?不推荐使用 DesiredCapabilities,我将如何在 selenium webdriver C# 中使用 SetCapability?
【发布时间】:2018-09-13 12:22:21
【问题描述】:

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

我可以这样用吗?

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

【问题讨论】:

  • 你尝试的时候发生了什么?
  • 返回执行错误。

标签: c# selenium selenium-webdriver automated-tests


【解决方案1】:

您应该使用特定于浏览器的“选项”类,而不是DesiredCapabilities,正如您的示例所示。但是,您只能调用 AddAdditionalCapability 来获取还没有类型安全属性或方法来设置能力值的能力名称。对于browserName 功能,已经有一个BrowserName 属性可以访问该功能的值。您收到的运行时异常应该具有要使用的属性或方法的名称,而不是使用该名称手动设置功能,但我认为存在一个错误,导致异常消息的格式不正确。

但是请注意,BrowserName 属性是只读的,因为由于您使用的是ChromeOptions,绑定已经知道浏览器名称应该是“chrome”。

【讨论】:

  • 非常感谢,您的帮助非常有用。
【解决方案2】:

在 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);
}

【讨论】:

  • 我不需要知道如何在云功能中执行浏览器配置。这不适合我的情况。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-05
  • 2021-12-20
  • 1970-01-01
  • 2020-05-22
  • 2018-12-05
相关资源
最近更新 更多