Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wait on handler registering - selenium

Tags:

selenium

There is a html page with button, and my selenium test is testing, that there is an action executed, when the button is clicked.

The problem is, that it looks like the click happens before the javascript is executed - before the handler is bound to the page. The consequence is, that the selenium test will click on the button, but no action happens.

I can solve this problem by repeatedly trying to click and then observe, if the desired action happened (some element is present on page, typically). I'd like to hear that there are some more elegant solutions...

like image 646
ryskajakub Avatar asked Dec 05 '13 13:12

ryskajakub


People also ask

How do I make Selenium wait 10 seconds?

We can make Selenium wait for 10 seconds. This can be done by using the Thread. sleep method. Here, the wait time (10 seconds) is passed as a parameter to the method.

How do you get the Selenium wait until the document is ready?

We can wait until the document is ready (page loaded completely) in Selenium by applying the method pageLoadTimeout. The wait time is passed as a parameter to this method. The webdriver waits for this duration for the page to load completely. If this time gets elapsed without page loading, a TimeoutException is thrown.

Which of the following command is a on event handler in Selenium?

EventHandler handler = new EventHandler(); eventDriver. register(handler);


1 Answers

There is no clear way to say "wait until element X has such-and-such handler"; this is a limitation of JavaScript and the DOM (see for example Get event listeners attached to node using addEventListener and jQuery find events handlers registered with an object), and for that matter a selenium Expected Condition can't be created, at least not trivially.

I've resorted to time.sleep(0.5).

like image 93
Antonis Christofides Avatar answered Oct 04 '22 19:10

Antonis Christofides