Prevent ruby selenium-webdriver from dismissing warnings when raising an UnhandledAlertError
Looking at the changelog for ruby selenium-webdriver I found this line numbered 2.18.0:
- Firefox and IE:
- Raise UnhandledAlertError if a warning is present during the operation. The unhandled warning is also dismissed to mitigate repeated exceptions.
This is a terrible change in my opinion. I like the exception, but any unhandled confirmations are fired (false is returned). I would really like to be able to save the exception and deal with the confirmation.
Unfortunately, I cannot find the code in the selenium-webdriver airplane, so I can overwrite this section and get rid of the startup warning command.
Is this anyway (other than returning my version)?
Thanks in advance,
Arth
source to share
I'm not 100% sure if this is what you want, but maybe I can help you anyway. The way I understand you is that you want to "force" the unhandled warnings to rescue.
When using an assertion like the find element function due to timeouts, I use the following code to find the element again.
!20.times { break if (selenium.is_visible(driver.find_element(:id, 'loginid')) rescue false ) ; sleep 1 }
The above loop will repeat 20 times (waiting 1 sec each time) in an attempt to find both the item and break when it finds it. Note that I haven't saved it yet as it is more durable to fit this in between start / end. Something like that..:
begin
!20.times { break if (selenium.is_visible(driver.find_element(:id, 'loginid')) rescue false ) ; sleep 1 }
[your executing code here] .
.
.
usr = driver.find_element(:id, 'loginid').click
usr = driver.find_element(:id, 'loginid').send_keys(username)
.
.
rescue
.
.
[your rescure code here]
.
.
puts "____________________________________________________________________"
puts "*** FATAL ERROR --> located at login area (username/password) ***"
puts "Possible reasons for this error..:"
puts "Invalid credentials * Cannot locate element id * "
puts "____________________________________________________________________"
.
end
Hope it helps!
source to share