[英]A bug in IE prevents my VBA macro from running
I have a VBA macro for fetching data from a web page that has been working fine for the past few months.我有一个 VBA 宏,用于从过去几个月一直运行良好的网页中获取数据。 This morning it stopped working.今天早上它停止工作。 The problem is that when I click a button to submit a form nothing happens.问题是,当我单击按钮提交表单时,什么也没有发生。 I tried to manually click the button without automation and still nothing happens.我尝试在没有自动化的情况下手动单击按钮,但仍然没有任何反应。
I looked it up and found this old thread which describes the problem: IE11-Only Submit Bug .我查了一下,发现了这个描述问题的旧线程: IE11-Only Submit Bug 。
So it appears that this is known issue with IE but that does not help me much.因此,这似乎是 IE 的已知问题,但这对我没有多大帮助。 Any suggestion on what can I do to have my macro running again?有什么建议可以让我的宏再次运行吗? Every tutorial I tried to read uses IE for automation so I am stuck here.我尝试阅读的每个教程都使用 IE 进行自动化,所以我被困在这里。
The following works using Chrome and selenium basic .以下作品使用 Chrome 和selenium basic 。 After installing selenium basic you need to go VBE>Tools>References and add a reference to Selenium Type Library
.安装 selenium basic 后,您需要转到 VBE>Tools>References 并添加对Selenium Type Library
的引用。 You have then removed IE from the equation.然后,您已从等式中删除了 IE。 Selenium basic supports a number of other browsers including FireFox and Opera. Selenium basic 支持许多其他浏览器,包括 FireFox 和 Opera。
Option Explicit
Public Sub EnterInfo()
Dim d As WebDriver, ele As Object, t As Date
Set d = New ChromeDriver
Const URL = "https://mypost.israelpost.co.il/%D7%9E%D7%A2%D7%A7%D7%91-%D7%9E%D7%A9%D7%9C%D7%95%D7%97%D7%99%D7%9D"
Const WAIT_TIME_SECS As Long = 10
With d
.Start "Chrome"
.get URL
With .FindElementById("ItemTraceForm")
.FindElementById("ItemCode").SendKeys 55671234
.FindElementById("btn-ItemCode").Click
t = Timer
Do
DoEvents
If Timer - t > WAIT_TIME_SECS Then Exit Do
Set ele = .FindElementById("result", timeout:=3000)
Loop While ele.Text = vbNullString
Debug.Print ele.Text
End With
'Other code....
Stop '<=Delete me later
.Quit
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.