Debugging Watir’s click_no_wait method problems
Update: Information in this post applies only to Watir 1.6.5 and older. If you’re using a newer version of Watir (i hope you do), then read this post instead!
There has been alot of problems with Watir’s click_no_wait method. It has been discussed widely in Watir’s Google Group.
This method is used for clicking html elements without waiting for the browser to finish. For example if you click some link which opens JavaScript popup then browser doesn’t finish before the popup has been dismissed. This is the place where click_no_wait should be used to click the link so your code won’t block and you can handle the popup. Otherwise, when just using plain click then your code would block forever.
Since there are alot of problems related with this functionality and almost no good solutions are proposed, then i thought that i might share some ideas how to find out the exact problem.
How does click_no_wait actually work?
It is a method of class Watir::Element as the regular click method, but the difference between them is that it invokes the regular click method in separate Ruby process - removing the problem of blocking. Since it is invoked in separate Ruby process then there isn’t any visible error messages to the user as with any other failing Watir command. I think that this is the main obstacle why people can’t understand the source of the problem and not fix it by themselves.
So, how to peek behind the doors?
- First, replace click_no_wait usage with click and see if the element is actually clicked or if the problem is with locating the element. If click doesn’t also work, then locate the element correctly and try again with click_no_wait.
- If the element is located correctly and regular clicking works, then locate your Watir’s source code. For me, the Watir 1.6.2 source code is located at:
C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib - Open watir/page_container.rb and look for the declaration of method called eval_in_spawned_process. The critical line is:
- Since “start” and “rubyw” are used then there’s no visible errors to the user as mentioned above. To find out the exact error message (if any) then it would be good to execute this command separately and see the results. You can do it by adding this line right after the line above:
- Now, start your test and try to use click_no_wait again. Leave the browser window opened with the page where you wanted to perform the operation. Open the created click_no_wait.txt file and change the part with “start rubyw” to just “ruby” and execute this command directly from your command line window. Now you should be able to see the exact error message that is shown if trying to perform the clicking operation.
- You can modify this command to perform some additional debugging commands like printing out the browser title, url or html or whatsoever to make sure that Watir has attached itself to the correct window and so on.




2 years ago