selenium - Winform 中的 Selenium Webdriver 和嵌入式浏览器 - 如何连接 web_driver 实例?
问题描述
我需要将 Selenium Webdriver 的实例连接/创建到我的测试应用程序在 Winform 中打开的 Web 内容。
我的测试框架使用 CodedUI 打开 Winform 应用程序,进一步的测试步骤导致 Winform 应用程序打开另一个 Winform 窗口,其中嵌入了浏览器。我需要创建或绑定一个 Selenium 实例到这个嵌入式浏览器内容。它在嵌入区域中使用 WebViewer/Edge。
注意 - 如果有的话,还没有准备好迁移到 WinAppDriver。
解决方案
解决了这个问题。我发现 Web 窗格是一个名为 WebView2 的对象。
在其中实现自动化需要以特殊方式启动应用程序:
Dim AppPath As String = "[full path to your app and its name].exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim AppStartInfo = New ProcessStartInfo(AppPath)
AppStartInfo.UseShellExecute = False
AppStartInfo.EnvironmentVariables("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS") = "--remote-debugging-port=9222"
Diagnostics.Process.Start(AppStartInfo)
您还需要:
- 项目中安装了 Selenium Support 和 Selenium Webdriver version 4.0.0-rc3
- msedgedriver 从这里:https ://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
最后在您的自动化代码中,当最终出现带有 WebView2 的窗口时,您需要运行此代码以将 selenium webdriver 绑定到 WebView2 窗格:
Dim driver As String = "[path to:]msedgedriver.exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim WebDriver = New EdgeDriver(EdgeDriverService.CreateDefaultService(".", driver), edgeOptions)
推荐阅读
- python - 你知道为什么过滤后的输出总是从零开始吗?辛辣过滤蟒蛇脑电图
- amazon-web-services - 如何使用 vpc 安全组来限制对我的 Lambda 的入站访问?
- python - 如何在 Python 中用烧瓶形式替换标准输入()
- azure - Azure AD 令牌验证 - 为什么要验证颁发者?
- javascript - 使用节点执行JS文件
- python - 如何使用熊猫将全天的每日数据重新采样为每小时数据?
- cx-oracle - 在 Pivotal CloudFoundry 上为 cx_Oracle 部署即时预言机
- laravel - 如何在 Laravel 中对部分模板进行模板化?
- angular - FullCalendar:调整大小事件在月视图中不起作用
- sql-server - 在查询中使用变量时无法查询并将数据放入游标中