Reputation: 73
In my test case, I need to wait for a few seconds to check if a particular element is visible or not. If the element is visible I need to perform a certain set of actions, if not visible then search for the next term and repeat the actions.
For this, I was trying to verify the presence of an element through isEnabled because isVisible does not wait for few second for the element to load !!
Upvotes: 0
Views: 607
Reputation: 1654
You can use wait_for_selector, problem is that wait for selector will throw an exception and then your test will stop, and you don't want to do that.
How can you solve that?
Defining your own function in a helper, and in case of exception (Your element is not visible) return false:
def my_own_wait_for_selector(page, selector, time_out):
try:
page.wait_for_selector(selector, timeout=time_out)
return True
except:
return False
Then you can use it for knowing if your element is visible in the DOM or not and take a decision/flow based on that
if helper.my_own_wait_for_selector(page, "MySelector", 5000):
#Whatever I want to do if element is there
else:
#Whatever I want to do if element is NOT there
I did it in python, but should be really simple to addapt it to javascript in case you are using different language.
Upvotes: 1