【发布时间】:2019-05-26 14:37:18
【问题描述】:
我正在开发用于 Excel VBA 的 Selenium Basic Wrapper,但是在单击打开新选项卡的按钮时,我无法让 selenium Web 驱动程序将焦点切换到打开的新选项卡上,并且关闭原始选项卡.. 相信这应该可以使用 Java Selenium 来实现,但是有没有办法通过 excel VBA 上的 Selenium Basic 包装器来做到这一点?
尝试使用 bot.switchtopreviouswindow/nextwindow 无济于事,Selenium 甚至似乎都没有检测到作为现有窗口打开的新选项卡/窗口,还尝试使用带有标题的 switchwindow 无济于事...
Private Sub CommandButton1_Click()
Dim bot As New ChromeDriver
Dim merchant As String
Dim promocode As Object
Dim number As Long
Dim test As Object
Dim testnumber As Integer
lastColumn = Sheets("Merchants").Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To lastColumn
bot.Get (Sheets("Merchants").Range("B" & i).Value)
merchant = Sheets("Merchants").Range("A" & i).Value
For Each promocode In bot.FindElementByClass("main_vouchers").FindElementsByClass("c")
number = Right(promocode.Attribute("id"), 6)
If IsEmpty(promocode) = True Then Exit For
promocode.FindElementByClass("go").Click
#This is the part I have problems with as after click, original page re-directs to another page, and new tab opens (which is the place I want focus on). Also, I need the original tab closed so that Chrome doesn't end up opening too many tabs due to the loop running. Appreciate the help!
Next promocode
Next i
End Sub
只需要 Selenium 将焦点切换到新打开的选项卡并关闭旧/原始选项卡..
【问题讨论】:
-
标签会有不同的名称可以使用吗?
标签: excel vba selenium selenium-webdriver selenium-chromedriver