如何在VB.NET中重新使用Selenium驱动程序实例?

时间:2018-08-09 06:52:22

标签: vb.net google-chrome selenium-webdriver automation

我想运行一个Windows窗体实用程序,该实用程序连接到以调试模式启动的Chrome,使用:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222

下面的代码运行良好,但是每次启动驱动程序时,都需要花费一些时间来启动Chrome驱动程序,我想反复通过Button1_Click测试自动化请求。

是否没有办法一次启动驱动程序,使其保持运行状态,而只是重新连接到该驱动程序实例以向其发送硒命令?

Imports System
Imports OpenQA.Selenium

Public Class Form1

Public Function ChromeDrv() As Chrome.ChromeDriver

    Dim ChromeOptions = New Chrome.ChromeOptions With
    {
        .DebuggerAddress = "localhost:9222"
    }

    ChromeDrv = New Chrome.ChromeDriver(ChromeOptions)

End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'Test321.FindElement(By.XPath("//div[@id=""home_maincap_v7""]/div[@class=""arrow left""]/div")).Click()
    MessageBox.Show(ChromeDrv.Title)

End Sub

结束班级

使用Visual Studio 2017社区版 Selenium.WebDriver V3.14.0 ChromeDriver 2.41 Google Chrome版本68.0.3440.106(正式版本)(64位) Windows 10

0 个答案:

没有答案