I am currently facing challenges while writing tests for a web application using Selenium with Ruby.
During my automated test, the selenium webdriver triggers a click on an element that executes some Javascript code.
This Javascript creates an alert window, which I usually handle by accepting it like this:
@IE.switch_to.alert.accept
However, in this scenario, the control is not returned to the Webdriver after triggering the alert, making it impossible for me to accept it.
It seems like the Javascript is still running and waiting for the alert to be accepted before completing its execution.
Since the Webdriver requires the Javascript to finish executing first before handling the alert, I am stuck in a situation where the alert cannot be accepted, and the Javascript will continue to run indefinitely.
Unfortunately, I do not have permission to modify the Javascript code, so the solution needs to come from the Selenium side.
Is there any way to execute the Javascript without making the Webdriver wait?
----UPDATE 1-----
Following a suggestion from a commenter, running the Javascript in a separate thread allowed me to regain control over the Webdriver: ************WRONG -- SEE UPDATE 2*******************
Thread.new{
button.press
}
However, I am unable to handle the alert as usual:
@IE.switch_to.alert
The above method is not working.
----UPDATE 2-----
Even when running the Javascript in a separate thread, its execution still blocks further actions by the Webdriver.
I am utilizing Selenium Grid to run tests remotely.
This means I cannot send keystrokes or any signals to the remote PC unless those methods are provided by the remote Webdriver. Moreover, since the Webdriver gets blocked by the Javascript even when executed in a separate thread, communication with the remote PC becomes impossible once the alert pops up.
One possible solution could be similar to what Murali suggested below - overriding the Javascript methods with ones that do not trigger alerts. However, this solution is not ideal as the Javascript methods I would need to override are complex and lengthy.
If anyone has insights or suggestions on how to tackle this issue, it would be greatly appreciated as it is hindering progress on our project.
Thank you!