Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Appropriate usage of accepting JS confirmation alerts? #811

Closed
sublimecoder opened this issue Jul 7, 2015 · 6 comments
Closed

Appropriate usage of accepting JS confirmation alerts? #811

sublimecoder opened this issue Jul 7, 2015 · 6 comments

Comments

@sublimecoder
Copy link

I apologize if this is not the place for this but, I just upgraded to the latest capybara webkit and previous to this upgrade I was able to use this syntax for javascript confirmation boxes.

page.driver.browser.accept_js_confirms

However this syntax appears that it is being deprecated.

The deprecation message says
[DEPRECATION] Capybara::Webkit::Driver#accept_js_confirms
is deprecated. Please use Capybara::Session#accept_confirm instead.

which should mean that I can swap the original code for this

page.accept_confirm

but that code appears to take a block and errors when you do not have one.

page.accept_confirm { }

What is the block used for in this case, or how should it be used?

@mhoran
Copy link
Collaborator

mhoran commented Jul 7, 2015

Hey @sublimecoder. You should provide a block which triggers a modal dialog. For example, if visit '/' would trigger a confirm dialog, you'd want to do the following:

page.accept_confirm { visit ('/') }

@sublimecoder
Copy link
Author

@mhoran Oh ok! That make sense! Just applied that and it worked!

Thank you so much!

@ghost
Copy link

ghost commented Jul 29, 2015

@mhoran ... I have tried the same but it didn't work.
getting error `rescue in find_modal': Unable to find modal dialog (Capybara::ModalNotFound)
I have tried all the options like....
page.driver.browser.evaluate_script('window.confirm = function() { return true; }')
page.driver.browser.switch_to.window(popup)

also send keys

builder = page.driver.browser.action
builder.send_keys(:escape).perform

But none of them work.

I need to click ok or cancel button of the dialog window.Please help

@mhoran
Copy link
Collaborator

mhoran commented Jul 31, 2015

Hey @ramugogurla. Are you sure you're using capybara-webkit? You're using some Selenium driver methods there and those are not compatible with capybara-webkit.

I'm going to close this out now as the original issue is solved. Please open a new issue if you are indeed using capybara-webkit.

@mhoran mhoran closed this as completed Jul 31, 2015
@TeTiRoss
Copy link

How to reject js dialog window?

@nritholtz
Copy link
Contributor

Checkout this comment #84 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants