【问题标题】:All Chrome open window names in VBAVBA中的所有Chrome打开窗口名称
【发布时间】:2020-10-27 17:01:11
【问题描述】:

我在 VBA 上有一个宏,在此过程中打开了几个 Chrome 窗口。 在每个窗口中,我需要执行不同的操作,为此我需要在它们之间切换。 我可以以某种方式获取打开的 Chrome 窗口的名称列表或 VBA 中的句柄吗? 此类方法在 VBA 中不起作用:

driver.getWindowHandles
driver.getWindowNames

在JS中,可以获取窗口名:

window_name = driver.ExecuteScript("return window.name;")

也许有一种方法可以获取所有窗口的名称并在 VBA 中循环浏览它们?

【问题讨论】:

    标签: vba selenium selenium-chromedriver


    【解决方案1】:

    我找到了或多或少解决此问题的方法。

    我们将每个要打开的窗口的名称保存在一个变量中

    window_count = driver.Windows.Count 'count all chrome windows
    
    i = 0
    For i = 1 To window_count 
        If driver.Windows.item(i).Title <> "SomeTitle 1" And driver.Windows.item(i).Title <> "SomeTitle 2" Then
            window_name = driver.Windows.item(i).Title 'at this moment the desired window is 
                                               'activated and you can work in it even
                                               'without driver.SwitchToWindowByTitle
             MsgBox driver.URL
        End If
    Next i
    

    我认为这不是解决问题的最佳方法,但据我所知,到目前为止我还不能这样做

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多