单击 VBA 脚本中的 Javascript 确认按钮
Clicking Javascript confirmation button in VBA script
我的代码的目的是 运行 在具有指定标准的网站上生成报告。我想搜索所有 "distance" 条件,这会提示一个消息框询问我是否确定。我希望我的代码能够单击 "Ok" 按钮。但是,一旦按下 "Submit" 按钮,我的代码就会停止 运行ning 并挂起,直到按下 "Ok" 按钮。
注意:我无法更改 HTML 或 JavaScript
这是VBA代码
Sub Data_Grab()
'Open Internet Explorer and webpage
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "insert website here"
'wait for page to finish loading
Do While IE.Busy
Loop
'get a reference to the search form by finding the id in the web page's object model
Dim daysAs Object
Dim city As Object
Set days= IE.Document.getElementByID("age"): days.Value = "10"
Set city= IE.Document.getElementByID("location"): city.Value = "LA"
'click the search button
With IE.Document
Set elems = .getElementsByTagName("input")
For Each e In elems
If (e.getAttribute("value") = "Submit") Then
e.Click
Exit For
End If
Next e
End With
End Sub
相关HTML/JavaScript代码来自网站源码
if (!distanceSelect) {
proceed = confirm("Are you sure you wish to search all " + question + "? Performance issues may occur.");
} else {proceed = true;}
和
<input class="contentarea" type="button" value="Submit" id="submit" onclick="javascript:loadReport();" />
我尝试过许多不同的解决方案,例如 SendKeys 和创建 ShellScript,但我无法让它们中的任何一个起作用。
谢谢。
一种方法是用 execScript
:
覆盖 confirm
Dim ie As Object, win As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://whosebug.com"
Do While ie.Busy: DoEvents: Loop
Set win = ie.Document.parentWindow
win.execScript "window.confirm = function(){return true;};"
我的代码的目的是 运行 在具有指定标准的网站上生成报告。我想搜索所有 "distance" 条件,这会提示一个消息框询问我是否确定。我希望我的代码能够单击 "Ok" 按钮。但是,一旦按下 "Submit" 按钮,我的代码就会停止 运行ning 并挂起,直到按下 "Ok" 按钮。
注意:我无法更改 HTML 或 JavaScript
这是VBA代码
Sub Data_Grab()
'Open Internet Explorer and webpage
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "insert website here"
'wait for page to finish loading
Do While IE.Busy
Loop
'get a reference to the search form by finding the id in the web page's object model
Dim daysAs Object
Dim city As Object
Set days= IE.Document.getElementByID("age"): days.Value = "10"
Set city= IE.Document.getElementByID("location"): city.Value = "LA"
'click the search button
With IE.Document
Set elems = .getElementsByTagName("input")
For Each e In elems
If (e.getAttribute("value") = "Submit") Then
e.Click
Exit For
End If
Next e
End With
End Sub
相关HTML/JavaScript代码来自网站源码
if (!distanceSelect) {
proceed = confirm("Are you sure you wish to search all " + question + "? Performance issues may occur.");
} else {proceed = true;}
和
<input class="contentarea" type="button" value="Submit" id="submit" onclick="javascript:loadReport();" />
我尝试过许多不同的解决方案,例如 SendKeys 和创建 ShellScript,但我无法让它们中的任何一个起作用。
谢谢。
一种方法是用 execScript
:
confirm
Dim ie As Object, win As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://whosebug.com"
Do While ie.Busy: DoEvents: Loop
Set win = ie.Document.parentWindow
win.execScript "window.confirm = function(){return true;};"