How to handle browser javascript confirm navigation alert with ruby watir script -
i'd programmatically handle javascript confirmation alert asking if you'd leave page (see screenshot below).
the methods i've tried far have not worked.
the browser not recognizing returning value true wanting leave page.
this part trying handle alert:
if @b.div(:class, "infomessagebox error").present? puts "there error" #@b.execute_script("window.confirm = function() {return true}") @b.execute_script("window.onbeforeunload = function() {};") @b.goto("#{@env}/translatefile.aspx") break end
i have read article: "dismiss "confirm navigation" popup watir" method in article not in case.
i apreciate because i'm stuck right here.
this helped in solving problem.
i improved code , works better here might other problems in future (hope not).
@b.refresh if @b.alert.exists? @b.alert.text @b.alert.ok end @b.goto("#{@env}/translatefile.aspx")
this helped me , escapes alert , continues workflow. ! :)
more info others might have trouble handling alerts ( link located below ):
# check if alert shown browser.alert.exists? # text of alert browser.alert.text # close alert browser.alert.ok browser.alert.close javascript confirms # accept confirm browser.alert.ok # cancel confirm browser.alert.close javascript prompt # enter text prompt browser.alert.set "prompt answer" # accept prompt browser.alert.ok # cancel prompt browser.alert.close # don't return alert browser.execute_script("window.alert = function() {}") # return string prompt simulate user entering browser.execute_script("window.prompt = function() {return 'my name'}") # return null prompt simulate clicking cancel browser.execute_script("window.prompt = function() {return null}") # return true confirm simulate clicking ok browser.execute_script("window.confirm = function() {return true}") # return false confirm simulate clicking cancel browser.execute_script("window.confirm = function() {return false}") # don't return leave page popup browser.execute_script("window.onbeforeunload = null")
answer is: can try use alternative method, such as: @b.alert.exists?
if return true
, then: @b.alert.close
i think this can in future
Comments
Post a Comment