无法点击网页中一些灰色的提交按钮
Unable to click on some grayed out submit button in a webpage
我在 vba 中创建了一个脚本,使用 IE 来填充网页中的一些输入以填充特定项目。
以下是我希望我的脚本执行的步骤:
- Select
Buy Bricks
来自着陆页
- 输入年龄 (35) 和国家(英国),然后单击
submit
按钮
- 在下一页,输入唯一标识号
对于
Element/design number
框中的乐高积木,例如 4219725
我的脚本可以满足前两个要求(点击提交按钮除外)。输入框都填好了,提交按钮还是灰色的。点击submit
按钮后,我希望满足第三个要求。
我的尝试:
Sub GetDetails()
Dim IE As New InternetExplorer, I As Long
Dim Html As HTMLDocument, post As Object, ageInput As Object
With IE
.Visible = True
.navigate "https://www.lego.com/en-gb/service/replacementparts"
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
Html.querySelectorAll(".arrow-list-info")(2).Click
Do: Set ageInput = Html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
ageInput.Focus
ageInput.innerText = 30
Do: Set post = Html.querySelector("select[ng-model='country']"): DoEvents: Loop While post Is Nothing
For I = 0 To post.Length - 1
If InStr(post(I).innerText, "United Kingdom") > 0 Then post(I).Selected = True: Exit For
Next I
End With
End Sub
如何激活变灰的提交按钮以便开始点击它?
向 select 元素添加更改事件
Option Explicit
Public Sub GetDetails()
Dim IE As New InternetExplorer, html As HTMLDocument, ageInput As Object
With IE
.Visible = True
.Navigate2 "https://www.lego.com/en-gb/service/replacementparts"
While .Busy Or .readyState < 4: DoEvents: Wend
Set html = .document
Dim event_onChange As Object
Set event_onChange = .document.createEvent("HTMLEvents")
event_onChange.initEvent "change", True, False
html.querySelectorAll(".arrow-list-info")(2).Click
Do: Set ageInput = html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
ageInput.innerText = 30
html.querySelector("[label='United Kingdom").Selected = True
IE.document.querySelector("select").dispatchEvent event_onChange
IE.document.querySelector("[ng-click='startFlow()'").Click
Do: Loop While IE.document.querySelectorAll("[ng-model=itemNumber]").Length = 0
IE.document.querySelector("[ng-model=itemNumber]").Focus
IE.document.querySelector("[ng-model=itemNumber]").Value = "4219725"
Stop
End With
End Sub
我在 vba 中创建了一个脚本,使用 IE 来填充网页中的一些输入以填充特定项目。
以下是我希望我的脚本执行的步骤:
- Select
Buy Bricks
来自着陆页 - 输入年龄 (35) 和国家(英国),然后单击
submit
按钮 - 在下一页,输入唯一标识号
对于
Element/design number
框中的乐高积木,例如4219725
我的脚本可以满足前两个要求(点击提交按钮除外)。输入框都填好了,提交按钮还是灰色的。点击submit
按钮后,我希望满足第三个要求。
我的尝试:
Sub GetDetails()
Dim IE As New InternetExplorer, I As Long
Dim Html As HTMLDocument, post As Object, ageInput As Object
With IE
.Visible = True
.navigate "https://www.lego.com/en-gb/service/replacementparts"
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
Html.querySelectorAll(".arrow-list-info")(2).Click
Do: Set ageInput = Html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
ageInput.Focus
ageInput.innerText = 30
Do: Set post = Html.querySelector("select[ng-model='country']"): DoEvents: Loop While post Is Nothing
For I = 0 To post.Length - 1
If InStr(post(I).innerText, "United Kingdom") > 0 Then post(I).Selected = True: Exit For
Next I
End With
End Sub
如何激活变灰的提交按钮以便开始点击它?
向 select 元素添加更改事件
Option Explicit
Public Sub GetDetails()
Dim IE As New InternetExplorer, html As HTMLDocument, ageInput As Object
With IE
.Visible = True
.Navigate2 "https://www.lego.com/en-gb/service/replacementparts"
While .Busy Or .readyState < 4: DoEvents: Wend
Set html = .document
Dim event_onChange As Object
Set event_onChange = .document.createEvent("HTMLEvents")
event_onChange.initEvent "change", True, False
html.querySelectorAll(".arrow-list-info")(2).Click
Do: Set ageInput = html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
ageInput.innerText = 30
html.querySelector("[label='United Kingdom").Selected = True
IE.document.querySelector("select").dispatchEvent event_onChange
IE.document.querySelector("[ng-click='startFlow()'").Click
Do: Loop While IE.document.querySelectorAll("[ng-model=itemNumber]").Length = 0
IE.document.querySelector("[ng-model=itemNumber]").Focus
IE.document.querySelector("[ng-model=itemNumber]").Value = "4219725"
Stop
End With
End Sub