【问题标题】:Selenium Webdriver and Embedded Browser in a Winform - How to connect web_driver instance?Winform 中的 Selenium Webdriver 和嵌入式浏览器 - 如何连接 web_driver 实例?
【发布时间】:2021-11-23 00:59:24
【问题描述】:

我需要将 Selenium Webdriver 的实例连接/创建到我的测试应用程序在 Winform 中打开的 Web 内容。

我的测试框架使用 CodedUI 打开 Winform 应用程序,进一步的测试步骤会导致 Winform 应用程序打开另一个 Winform 窗口,其中嵌入了浏览器。我需要创建或绑定一个 Selenium 实例到这个嵌入式浏览器内容。它在嵌入区域中使用 WebViewer/Edge。

注意 - 尚未准备好迁移到 WinAppDriver,如果有的话。

【问题讨论】:

    标签: selenium webdriver


    【解决方案1】:

    解决了这个问题。我发现 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) 
    

    你还需要:

    最后在您的自动化代码中,当最终出现包含 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)
    

    【讨论】:

      猜你喜欢
      • 2019-09-19
      • 1970-01-01
      • 2021-11-23
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      • 2017-08-16
      相关资源
      最近更新 更多