I am writing tests for a web application using Selenium on top of Ruby and I have run into some trouble.
In my automated test, selenium webdriver clicks on an element, which in turn, executes some Javascript.
The Javascript creates an alert window, which I would usually accept with:
@IE.switch_to.alert.accept
In this case however, control is not passed back to the Webdriver and I am unable to accept the alert.
It seems as if the Javascript is still executing - probably just waiting for the alert to be accepted.
But because the webdriver requires the javascript to finish executing BEFORE it can accept the alert, the alert can not be accepted and the javascript will never finish executing.
I do not have permission to modify the Javascript so the fix must be on the selenium side.
Is there any way I can execute the Javascript without forcing the webdriver to wait for it?
----UPDATE 1-----
As a commenter suggested running the javascript in a separate thread has enabled me to regain control with the webdriver: ************WRONG -- SEE UPDATE 2*******************
Thread.new{
button.press
}
Unfortunately I cannot handle the alert as I usually would:
@IE.switch_to.alert
^ is not working
----UPDATE 2-----
Even when run in a thread, the execution of the javascript still blocks any further execution by the webdriver.
I am using Selenium Grid to execute the tests remotely.
Because of this, I am unable to send keystrokes or any kind of signal to the remote PC unless that method is provided by the remote webdriver, and since the webdriver is blocked by the Javascript execution (even if it is running in a separate thread) I am unable to communicate with the remote PC once the alert is thrown.
The closest idea I have for a solution is like what Murali suggested below, and overide the javascript methods with ones that do not return alerts. However this is very far from ideal, the javascript methods I would be overriding are numerous and complex, some of them are hundreds of lines long.
If anybody has anything to suggest on this matter it would be hugely appreciated as this issue is blocking any further progress on our project.
Thanks!