excel - 从下拉列表中选择后出现意外的 Selenium 行为

标签 excel vba selenium selenium-webdriver web-scraping

我在 VBA 中编写了一个 Selenium 脚本以从下拉列表中进行选择,然后按 Done按钮。

默认页面显示Bangladesh在它的登陆页面中。我需要将其更改为 Canada .

我的脚本从下拉列表中选择所需的国家,但当它应该单击 Done按钮,它会点击其他地方,因此国家/地区保持不变。该脚本没有显示任何错误。

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

这就是它在登录页面中显示的内容。

enter image description here

最佳答案

似乎在最后一次点击之前需要稍作喘息。

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

关于excel - 从下拉列表中选择后出现意外的 Selenium 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52862083/

相关文章:

javascript - 将内容从 Excel 粘贴到 Chrome

excel - 如何在 VBA 函数的 VBA 函数结果上强制使用 NumberFormat?

python - 按钮未被点击

Excel VBA - 刷新选定的查询/连接

excel - 按字符串中倒数第二个字符实例修剪

excel - 在excel中分段

vba - 查找字典中某个项目对应的键

sql - Excel Vba - 在 sql 字符串中使用撇号

java - Selenium 与 Java : Elements in a pop-up are not recognized

java - Selenium,点击元素,挂起