使用硒很容易,但我需要通过正确的设置启动驱动程序
所以现在我只需要忽略缩放级别
我的代码是:
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);
如何正确传递功能和驱动程序路径?
答案 0 :(得分:8)
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);