我有一个带有Selenium WebDriver的VBA代码,它从SELECT OPTIONs中提取一些文本。当我进行选择时,页面会重新加载,但我的代码不会等待页面加载,并会出现意外错误。我应该怎么做才能让它等到页面加载后再进一步移动?
Col = "I"
For Each Cel In SH.Range(Col & "2:" & Col & SH.Cells(SH.Rows.Count, Col).End(xlUp).Row)
Set CD = New Selenium.ChromeDriver
With CD
.Start
.Get "https://store.majic-paper.com/store/product-view.html/" & Cel.Value
Set Sizes = .FindElementByCss("#product").FindElementsByCss("option")
ReDim Arr(Sizes.Count)
x = 0
'making array of the options to be selected in next for each loop
For Each Size In Sizes
x = x + 1
Arr(x) = Size.Text
Next Size
For x = 1 To Sizes.Count
dr = dr + 1
dSH.Cells(dr, "A") = Cel.Value
dSH.Cells(dr, "B") = Arr(x)
Set sizez = .FindElementByCss("#product").AsSelect
sizez.SelectByText Arr(x) ' here as soon as it selects an item the page gets reloaded therefore do not give a chance to find the nam(Quantity) in next line
'Quantity
Set Q = .FindElementByName("Quantity").FindElementByCss("option")
dSH.Cells(dr, "C") = Q.Text
我想我想通了。我没有VBA Selenium,所以你必须尝试一下,看看它是否有效。
Set sizez = .FindElementByCss("#product").AsSelect
sizez.SelectByText Arr(x)
' wait for the "Please wait" spinner to appear and then disappear
.IsElementPresent(By.XPath("//h2[contains(.,'Please wait')]"), 5000)
.WaitNotElement(By.XPath("//h2[contains(.,'Please wait')]"), 5000)
'Quantity
Set Q = .FindElementByName("Quantity").FindElementByCss("option")
dSH.Cells(dr, "C") = Q.Text