使用选项和功能设置selenium Web驱动程序

本文关键字:selenium Web 驱动程序 设置 功能 选项 | 更新日期: 2023-09-27 18:20:31

使用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);

如何正确地通过功能和驱动程序路径?

使用选项和功能设置selenium Web驱动程序

IE选项有一个InternetExplorerOptions类,请参阅source,它有一个方法AddAdditionalCapability。但是,对于ignoreZoomSetting,该类已经提供了一个名为IgnoreZoomLevel的属性,因此不需要设置功能。

另一方面,InternetExplorerDriver为IEDriver和InternetExplorerOptions的路径都有一个构造函数。源

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