gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:30:59 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com