Reputation: 22440
I've written a Selenium script in VBA to select from a dropdown then press the Done
button.
By default the page shows Bangladesh
in it's landing page. I need to change it to Canada
.
My script selects the desired country from the dropdown but when it is supposed to click the Done
button, it clicks elsewhere so the country remains unchanged. The script doesn't show any error.
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.
Upvotes: 1
Views: 86
Reputation: 84465
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
Upvotes: 2