I've written a script in vba in association with selenium to select a country (Canada) from a dropdown and pressing the Done button when it's done. By default the page shows Bangladesh in it's landing page. All I need to do is change it to Canada. My below script can select that desired country from the dropdown but after that when It is supposed to click the Done button, It clicks elsewhere so the option remains unchanged. How can I do so? Btw, the script doesn't show any error.

Site link:

Sub SelectDropdown()
    Dim driver As New ChromeDriver

    With driver
        .get "https://www.amazon.com/dp/B071V5DQ56/"
        .FindElementByCss("#nav-packard-glow-loc-icon", timeout:=5000).Click
        .FindElementByCss("#GLUXCountryListDropdown", timeout:=5000).Click
        .FindElementById("GLUXCountryList", timeout:=5000).AsSelect.SelectByText "Canada"
        .FindElementByCss("div.a-popover-wrapper button[name='glowDoneButton']", timeout:=5000).Click
    End With
    Stop
End Sub

This is what it shows in the landing page. I need to change the country name to Canada.

enter image description here

1 Answers

2
QHarr On Best Solutions

Seems like it needs a little breather before the final click.

Option Explicit
Public Sub SelectDropdown()
    Dim driver As New ChromeDriver
    With driver
        .get "https://www.amazon.com/dp/B071V5DQ56/"
        .FindElementByCss("#nav-packard-glow-loc-icon", timeout:=5000).Click
        .FindElementByCss("#GLUXCountryListDropdown", timeout:=5000).Click
        .FindElementById("GLUXCountryList", timeout:=5000).AsSelect.SelectByText "Canada"
        Application.Wait Now + TimeSerial(0, 0, 1)
        .FindElementByCss("[data-action='a-popover-close']", timeout:=5000).Click
    End With
End Sub