Logic to adopt when an webelement is showing and desapearring two times

29 Views Asked by At

I'm struggling with something right now and I don't know how to solve this.

Using Selenium and Helium, I'm running some test on a web app.

At some point, the web app print a screen blocker. This screen locker appears and disappears two times.

I have to wait for the second one to disappear to move on to other stuff.

How can I do this?

Code I've tried :

while S(".loadingHeader").exists:
    print ("loading")

This piece of code is working for the first time the screen blocker is appearing

I'm taking any idea you have.

Thank you and have a nice day

2

There are 2 best solutions below

0
On BEST ANSWER

Thank you for your answer.

I ended up doing this :

wait_until (S(".loadingHeader").exists)
time_open = time.time()
while S(".loadingHeader").exists():
    time.sleep(0.5)
    print ("Loading")
if (lambda : not S(".loadingHeader").exists):
    wait_until (S(".loadingHeader").exists)
    print ("Loading Again")
    while S(".loadingHeader").exists():
        print ("Loading")
        time.sleep(0.5)
tmp_time_open = (time.time() - time_open)
print ("Not Loading Anymore !!!")
print ("Opening in : " + str(tmp_time_open))

It's working that way. Hope it will be usefull to someone else

0
On

If you want it to just appear and disappear, you could just replace the first print with a blank string and then print a second message after putting a time.sleep(2). After the second message you can do the same.

Here for example:

import time
msg = "loading"
print(msg)
# Set the amount of seconds you want to wait
time.sleep(2)
print(" " * len(msg))