功能和 EdgeOptionsCapabilities and EdgeOptions

功能是您可以用于自定义和配置会话 EdgeDriver 的选项。Capabilities are options that you may use to customize and configure an EdgeDriver session. 若要了解如何启动新 EdgeDriver 会话,请导航到"自动化 Microsoft Edge"。To learn about starting a new EdgeDriver session, navigate to Automating Microsoft Edge. 本文介绍了 Microsoft Edge 的所有受支持的功能,并详细介绍了将这些功能传递到 EdgeDriver 会话。This article describes all supported capabilities for Microsoft Edge and details on passing the capabilities to EdgeDriver sessions.

功能作为 JSON 映射传递到 WebDriver 会话。Capabilities are passed to a WebDriver session as a JSON map. WebDriver 语言绑定通常提供类型安全的便利方法,因此无需自己配置 JSON 映射。WebDriver language bindings typically provide type-safe convenience methods so you don't need to configure the JSON map yourself. 不同的 WebDriver 语言绑定使用不同的机制来配置功能。Different WebDriver language bindings use different mechanisms to configure capabilities. 导航到首选语言绑定 的文档, 详细了解如何配置功能。Navigate to the documentation for your preferred language binding to learn more about how to configure capabilities. Selenium 通过 类配置 EdgeOptions 功能。Selenium configures capabilities through the EdgeOptions class.

使用 EdgeOptions 类Using the EdgeOptions class

创建 的实例 EdgeOptions ,这将提供设置 Microsoft Edge 特定功能的便利方法。Create an instance of EdgeOptions, which provides convenience methods to set Microsoft Edge-specific capabilities. 配置对象后 EdgeOptions ,传递到 EdgeOptions EdgeDriver 构造函数。After you configure the EdgeOptions object, pass EdgeOptions into the EdgeDriver constructor.

var options = new EdgeOptions();
options.UseChromium = true;
options.AddExtensions("/path/to/extension.crx");
var driver = new EdgeDriver(options);

若要使用没有关联的便利方法的功能,请使用 AddAdditionalCapability 方法。To use capabilities that don't have an associated convenience method, use the AddAdditionalCapability method. 您必须传递功能的完整名称和正确类型的值。You must pass the full name of the capability and a value with the correct type. 若要查看接受的功能和值类型的完整列表,请导航到 EdgeOptions 对象To review the full list of accepted capabilities and value types, navigate to EdgeOptions object.

options.AddAdditionalCapability("wdpAddress", "remotehost:50080");

可识别的功能Recognized Capabilities

有关接受的标准 EdgeDriver 功能,请导航到 Selenium 文档W3C WebDriver 标准For standard capabilities that EdgeDriver accepts, navigate to Selenium documentation and the W3C WebDriver standard. 本文仅列出了特定于 Microsoft Edge 的功能。This article only lists capabilities specific to Microsoft Edge.

EdgeOptions 对象EdgeOptions object

大多数特定于 Microsoft Edge 的功能都通过 对象 EdgeOptions 公开。Most Microsoft Edge-specific capabilities are exposed through the EdgeOptions object. 在某些语言中,这些功能由 类 EdgeOptions 实现。In some languages, the capabilities are implemented by the EdgeOptions class. 在其他语言中,这些功能存储在 中的 ms:edgeOptions 字典下 DesiredCapabilitiesIn other languages, the capabilities are stored under the ms:edgeOptions dictionary in DesiredCapabilities.

功能Capability 类型Type 默认值Default value 详细信息Details
argsargs 字符串列表list of strings 启动 Microsoft Edge 时使用的命令行参数列表。List of command-line arguments to use when starting Microsoft Edge. 具有关联值的参数应用 = 符号 \ (例如 ['start-maximized', 'user-data-dir=/tmp/temp_profile'] ) 。Arguments with an associated value should be separated by a = sign (for example, ['start-maximized', 'user-data-dir=/tmp/temp_profile']).
binarybinary 字符串string 在 macOS 上使用 \ (的 Microsoft Edge 二进制文件的路径,路径应为实际的二进制文件,而不只是应用。Path to the Microsoft Edge binary to use (on macOS, the path should be the actual binary, not just the app. 例如 /Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge ,) 。for example, /Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge).
debuggerAddressdebuggerAddress 字符串string 要连接到的调试器服务器的地址,格式为 hostname/ip:port ,例如 127.0.0.1:38947An address of a debugger server to which to connect, in the form of hostname/ip:port, for example 127.0.0.1:38947.
分离detach 布尔型boolean false 如果为 ,则 Microsoft Edge 在 WebDriver 服务关闭时退出,即使 false WebDriver 本地端尚未关闭会话。If false, Microsoft Edge quits when the WebDriver service shuts down, even if the WebDriver local end hasn't closed the session. 如果 true 为 ,Microsoft Edge 仅在 WebDriver 本地端关闭会话时退出。If true, Microsoft Edge only quits if the WebDriver local end closes the session. 如果 为 ,并且 WebDriver 本地端不关闭会话,则不清理 Microsoft Edge 实例使用的临时 true EdgeDriver 用户数据文件夹。If true, and the WebDriver local end does not close the session, EdgeDriver does not clean up the temporary user data folder used by the Microsoft Edge instance.
excludeSwitchesexcludeSwitches 字符串列表list of strings 启动 Microsoft Edge 时,默认情况下会传递用于排除该 EdgeDriver 的 Microsoft Edge 命令行开关列表。List of Microsoft Edge command line switches to exclude that EdgeDriver by default passes when starting Microsoft Edge. 避免 -- 使用开关前缀。Avoid the -- prefix for switches.
extensionsextensions 字符串列表list of strings 启动时要安装的扩展的列表。A list of extensions to install on startup. 列表中的每个项目应为 Base64 编码的打包扩展 \ (.crx ) 。Each item in the list should be a base-64 encoded packed extension (.crx).
localStatelocalState 字典dictionary 包含每个条目的字典,包含首选项的名称和值。A dictionary with each entry consisting of the name of the preference and the value. 首选项将应用于用户数据文件夹中的本地状态文件。The preferences are applied to the Local State file in the user data folder.
minidumpPathminidumpPath 字符串string 用于存储 Microsoft Edge 小型dumps的目录。Directory to store Microsoft Edge minidumps. \ (仅在 Linux 上受支持。) (Supported only on Linux.)
mobileEmulationmobileEmulation 字典dictionary 值为 的字典, deviceName 或和 deviceMetrics 的值 userAgentA dictionary with either a value for deviceName, or values for deviceMetrics and userAgent.
perfLoggingPrefsperfLoggingPrefs 字典dictionary 指定性能日志记录首选项的可选字典。An optional dictionary that specifies performance logging preferences. 有关详细信息,请导航到 perfLoggingPrefs 对象for more information, navigate to perfLoggingPrefs object.
prefsprefs 字典dictionary 包含每个条目的字典,包含首选项的名称和值。A dictionary with each entry consisting of the name of the preference and the value. 首选项仅适用于使用的用户配置文件。The preferences are only applied to the user profile in use. 例如,导航到 Preferences Microsoft Edge 的用户数据文件夹中的文件。For examples, navigate to the Preferences file in the user data folder of Microsoft Edge.
wdpAddresswdpAddress 字符串string 连接到的 Windows Device Portal 服务器的地址,格式为 hostname/ip:port ,例如 127.0.0.1:50080An address of a Windows Device Portal server to which you connect, in the form of hostname/ip:port, for example 127.0.0.1:50080. 有关详细信息,请导航到远程 调试 - Windows 10 设备For more information, navigate to Remote Debugging - Windows 10 devices.
wdpPasswordwdpPassword 字符串string 连接到 Windows Device Portal 服务器时使用的可选密码。Optional password to use when connecting to a Windows Device Portal server. 如果服务器已启用身份验证,则必需。Required if the server has authentication enabled.
wdpUsernamewdpUsername 字符串string 连接到 Windows Device Portal 服务器时使用的可选用户名。Optional user name to use when connecting to a Windows Device Portal server. 如果服务器已启用身份验证,则必需。Required if the server has authentication enabled.
windowsAppwindowsApp 字符串string 要启动的 Microsoft Edge 应用包的应用程序用户模型 ID,例如 Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe!MSEDGEApplication user model ID of a Microsoft Edge app package to launch, for example Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe!MSEDGE. 使用 windowsApp Windows Device Portal 连接到 Windows binary 10X 设备或仿真器时,使用 而不是 。Use windowsApp instead of binary when connecting to a Windows 10X device or emulator using Windows Device Portal.
windowTypeswindowTypes 字符串列表list of strings 窗口句柄列表中显示的窗口类型列表。A list of window types that are displayed in the list of window handles. 若要访问 Android webview 元素,请 webview 包含到列表中。For access to Android webview elements, include webview in the list.

perfLoggingPrefs 对象perfLoggingPrefs object

词典 perfLoggingPrefs 具有以下格式 \ (所有键都是可选的) 。The perfLoggingPrefs dictionary has the following format (all keys are optional).

Key 类型Type 默认值Default value 详细信息Details
bufferUsageReportingIntervalbufferUsageReportingInterval 正整数positive integer 10001000 DevTools 跟踪缓冲区使用事件之间请求的毫秒数。The requested number of milliseconds between DevTools trace buffer usage events. 例如,如果为 1000,则每秒一次,DevTools 将报告跟踪缓冲区的已满。For example, if 1000, then once per second, DevTools reports how full the trace buffer is. 如果报告指示缓冲区使用率为 100%,则发出警告。If a report indicates the buffer usage is 100%, a warning is issued.
enableNetworkenableNetwork 布尔型boolean truetrue 从网络 (收集 ) 事件。To collect (or not collect) events from Network domain.
enablePageenablePage 布尔型boolean truetrue 从页面 (收集 ) 事件。To collect (or not collect) events from Page domain.
traceCategoriestraceCategories 字符串string \ (empty) (empty) Microsoft Edge 跟踪类别的逗号分隔字符串,应收集跟踪事件。A comma-separated string of Microsoft Edge tracing categories for which trace events should be collected. 未指定或空字符串禁用跟踪。An unspecified or empty string disables tracing.

返回的功能Returned capabilities

以下列表包含在创建新会话时返回的所有特定于 Microsoft Edge EdgeDriver 的功能。The following list contains all of the Microsoft Edge-specific capabilities that EdgeDriver returns when you create a new session.

功能Capability 类型Type 详细信息Details
msedge.msedgedriverVersionmsedge.msedgedriverVersion 字符串string EdgeDriver 的版本。The version of EdgeDriver.
msedge.userDataDirmsedge.userDataDir 字符串string Microsoft Edge 实例使用的用户数据文件夹的路径。The path to the user data folder used by the Microsoft Edge instance.