【问题标题】:Open new Chrome tab打开新的 Chrome 标签页
【发布时间】:2019-09-04 02:06:23
【问题描述】:

美好的一天。 您能否通过打开 Chrome 浏览器创建新标签页、在其中执行一些操作、关闭新标签页然后返回第一个标签页并继续在其中工作来判断 Selenium VBA 是否可行?

我用这段代码打开浏览器:

Public drv As New WebDriver

Public Sub browser_open()
Set drv= New WebDriver 'ChromeDriver
drv.Start "chrome", "https://google.com"
drv.Get "/"

End Sub

【问题讨论】:

    标签: excel vba selenium web-scraping selenium-chromedriver


    【解决方案1】:

    你可以这样做:

    'Ensure latest applicable driver e.g. ChromeDriver.exe in Selenium folder
    'VBE > Tools > References > Add reference to selenium type library
    Public Sub DownloadFile()
        Dim d As WebDriver
        Set d = New ChromeDriver
        Const URL = "https://stackoverflow.com/"
    
        With d
            .Start "Chrome"
            .get URL
            .ExecuteScript "window.open('https://www.google.com/','_blank');"
            .SwitchToNextWindow
            'do something with new window
            Debug.Print .Window.Title
            .ExecuteScript "window.close();"
            .SwitchToPreviousWindow
            Debug.Print .Window.Title
            Stop
            .Quit
        End With
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2012-03-23
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 2014-05-05
      • 2011-06-26
      相关资源
      最近更新 更多