Reputation: 493
I'm using watir-webdriver and i'm having trouble with a confirmation popup. I click on a 'Sell' button and a confirmation popup appears. I can't seem to figure out how to come up with the step to click 'OK' on the popup. Any help would be much appreciated.
The html in question is: (Button)
<button>class="btn primary" onclick="return confirm('Are you sure you wish to sell the selected loan parts?');" value="Sell Loan Parts" name="sell_loan_parts" style="" type="submit"</button>
I tried using following step, but I guess this is incorrect:
@browser.button(:onclick, "return confirm('Are you sure you wish to sell the selected loan parts?');").click
Error message I recieve is:
Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
[remote server] file:///var/folders/fd/hjkxr06j6gs6620tl4k_9fh00000gn/T/webdriver-profile20121129-50930-ul24fl/extensions/[email protected]/components/command_processor.js:10402:in `unknown'
Upvotes: 2
Views: 5011
Reputation: 4210
Might also be of help to recall the browser to set focus to the modal window (when using Selenium Webdriver and Cucumber, for example). This has worked for me in the past when nothing else has. All you have to do is this:
browser = GemName::CucumberFormatter::Browser.get_browser
browser.alert.ok
It's just another option.
Upvotes: 1
Reputation: 46836
Watir has an api for handling these types of javascript alerts. Some useful links:
You should be able to click OK in the confirm by doing:
@browser.alert.ok
Upvotes: 4