我正在填写一个Web表单,其中包含一个内置的预加载器动画(不影响浏览器状态),我正在尝试让我的脚本等待它消失,然后才继续填补领域。
目前我正在使用此代码:
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")消失?
提前谢谢。
答案 0 :(得分:0)
所以,这就是我所做的,代码的第一部分是等待Preloader出现,当它出现时,第二部分正在等待Preloader消失。
这个解决方案现在似乎运行得很好,我希望如果页面加载速度低于预期,就不会出现任何其他问题:)
Do
Set el = Nothing
On Error Resume Next
Set el = objIE.document.getElementsByClassName("preloader__loader")(0)
On Error GoTo 0
DoEvents
Sleep 500
Loop While el Is Nothing
Do
Set el = Nothing
On Error Resume Next
Set el = objIE.document.getElementsByClassName("preloader__loader")(0)
On Error GoTo 0
DoEvents
Sleep 500
Loop While Not (el Is Nothing)