Selenium Basic to wait for the web page to be reloaded after selection from the drop down list and page update

Viewed 31

I have this VBA code with Selenium WebDriver that extracts some text from SELECT OPTIONs. When I make a selection, the page reloads but my code does not wait for the page to load and gives an unexpected error. What should I do to make it wait until the page is loaded to move further?

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
1 Answers

I think I figured it out. I don't have VBA Selenium so you'll have to try this and see if it works.

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
Related