虽然我需要通过正确的设置启动驱动程序,但使用 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/