0

I am filling a web form, which has an built-in preloader animation (which does not impact the browser states) in it, and I am trying to make my script wait for it to be gone, and only then proceed with filling the fields.

Currently I am using this code:

 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

Not sure why, but still, sometimes this code is not working properly and the Submit button (button_submit) is not pressed.

I would like to avoid wait sentences as much as I can, as they are unreliable in times the page is loading slowly.

Are there any better ways for script to wait for a particular elements (in this case "preloader__loader") to disappear?

Thank you in advance.

Community
  • 1
  • 1
Kestas
  • 43
  • 2
  • 9
  • The link to the web form might be helpful to include. – QHarr Feb 13 '18 at 16:06
  • Sadly, this is not possible, the website is only available through internal network – Kestas Feb 13 '18 at 17:16
  • First of all remove `On Error Resume Next` since you don't control what is the error occurs if it does. Create the code which is able to check all the necessary states to avoid errors. E. g. check `.getElementsByClassName("preloader__loader").length`. – omegastripes Feb 13 '18 at 17:29

1 Answers1

0

So, here is what I did, the first part of the code is waiting for Preloader to appear, and when it does, second part is waiting for the Preloader to disappear.

This solutions seems to be working quite good for now, I hope there would not be any additional issues if the page will be loading slower than expected :)

      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)
Kestas
  • 43
  • 2
  • 9