c# - 使用选项和功能设置 selenium Webdriver

标签 c# asp.net selenium selenium-webdriver automation

虽然我需要通过正确的设置启动驱动程序,但使用 selenium 很容易

所以现在我只需要它忽略缩放级别

我的代码是:

public string path = AppDomain.CurrentDomain.BaseDirectory;
public IWebDriver WebDriver;
var ieD = Path.Combine(path, "bin");

DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
caps.SetCapability("ignoreZoomSetting", true);

现在我当前的代码只是将驱动程序的路径作为参数传递

WebDriver = new InternetExplorerDriver(ieD);

我怎样才能正确传递功能和驱动程序路径?

最佳答案

IE 选项有一个 InternetExplorerOptions 类,See source ,它有一个方法 AddAdditionalCapability。但是,对于您的 ignoreZoomSetting,该类已经提供了一个名为 IgnoreZoomLevel 的属性,因此您无需设置功能。<​​/p>

另一方面,InternetExplorerDriver 有一个用于 IEDriver 和 InternetExplorerOptions 路径的构造函数。 Source

public InternetExplorerDriver(string internetExplorerDriverServerDirectory, InternetExplorerOptions options)

使用方法如下:

var options = new InternetExplorerOptions {
    EnableNativeEvents = true, // just as an example, you don't need this
    IgnoreZoomLevel = true
};

// alternative
// var options = new InternetExplorerOptions();
// options.IgnoreZoomLevel = true;


// alternatively, you can add it manually, make name and value are correct
options.AddAdditionalCapability("some other capability", true);

WebDriver = new InternetExplorerDriver(ieD, options);

关于c# - 使用选项和功能设置 selenium Webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17390520/

相关文章:

c# - 如何在不显示/显示的情况下打印 Windows 窗体

c# - 我可以在不禁用 FIPS 合规性的情况下使用 WPF 吗?

python - LiveServerTestCase - settings.Database 配置不正确

javascript - 使用 Selenium 从 Javascript 网页派生文本

python - 如何在Python中使用NordVPN?

c# - 大表的最佳主键格式

c# - 使用数据库文件在 Azure Devops 上运行测试

c# - IE7/8 : PDF file won't download with HTTP GET

JavaScript window.location 不起作用

c# - dropdownlist onchange 事件未触发