【发布时间】:2018-02-13 16:01:30
【问题描述】:
我正在填写一个网络表单,其中有一个内置的预加载器动画(不会影响浏览器状态),我试图让我的脚本等待它消失,然后才继续填写字段。
目前我正在使用此代码:
Do
Set el = Nothing
On Error Resume Next
Set el = objIE.document.getElementsByClassName("preloader__loader")(0)
On Error GoTo 0
DoEvents
Sleep 2000
Loop While Not (el Is Nothing)
objIE.document.getElementsByName("button_submit")(0).Click
不知道为什么,但有时此代码无法正常工作,并且未按下提交按钮 (button_submit)。
我想尽可能避免等待语句,因为在页面加载缓慢时它们是不可靠的。
有没有更好的方法让脚本等待特定元素(在本例中为“preloader__loader”)消失?
提前谢谢你。
【问题讨论】:
-
包含网络表单的链接可能会有所帮助。
-
很遗憾,这是不可能的,网站只能通过内网访问
-
首先删除
On Error Resume Next,因为您无法控制如果发生错误会发生什么。创建能够检查所有必要状态以避免错误的代码。例如。检查.getElementsByClassName("preloader__loader").length。
标签: vba excel ie-automation