Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  107] [ 4]  / answers: 1 / hits: 23696  / 13 Years ago, sun, february 19, 2012, 12:00:00

I have a page with something like this:



<input type=button onclick=confirm('confirm popup'); value=click />


When I go to the page and click the link:



require watir-webdriver
browser = Watir::Browser.new
browser.goto page.html
browser.button.click


confirm popup appears. I can dismiss it with this:



require watir-webdriver/extensions/alerts
browser.confirm(true) {browser.button(:value => 'Confirm').click}


but the I get this error message:



[remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/command_processor.js:10302:in `unknown': Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/driver-component.js -> file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/dispatcher.js:85:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/driver-component.js -> file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/dispatcher.js:516:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/driver-component.js -> file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/dispatcher.js:351:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/driver-component.js -> file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/webdriverserver.js:47:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:1935:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:2261:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:1168:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:1616:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:1464:in `unknown'
from [remote server] file:///var/folders/yx/bz_81fc143b4r9pyhks300m00000gn/T/webdriver-profile20120218-1562-7b7q8d/extensions/[email protected]/components/httpd.js:1333:in `unknown'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:590:in `raw_execute'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:568:in `execute'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/remote/bridge.rb:314:in `executeScript'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.19.0/lib/selenium/webdriver/common/driver.rb:209:in `execute_script'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.5.3/lib/watir-webdriver/browser.rb:129:in `execute_script'
from /Users/zeljko/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.5.3/lib/watir-webdriver/extensions/alerts.rb:39:in `confirm'
from popup.rb:7:in `<main>'


What am I doing wrong?



Environment:




  • Mac OS X 10.7.3

  • Firefox 10.0.2

  • Ruby 1.9.3p125

  • selenium-webdriver 2.19.0

  • watir-webdriver 0.5.3


More From » popup

 Answers
53

I'll refer you to this answer https://stackoverflow.com/a/8172888/409820 where I explained about using methods like browser.confirm. The examples of which are a bit confusing since they come straight from the tests, and if you don't understand the context that there were multiple buttons on the test page, and the one that causes a confirm dialog has a value of 'confirm' then the 'inner' command wrapped by the method doesn't make a lot of sense.



The commands in the loop (or block ) following the confirm method is the command that causes the popup to occur.



Hence a better example of how to use those methods would have been something like



alert_message_text = browser.confirm(true) do
#watir code that causes confirm popup goes here
end


or



alert_message_text = browser.confirm(true) {#code that causes confirm popup}


in other words the way this works using .confirm(response) {block} is a lot like telling watir ok the command I am giving you in the block will cause a confirm dialog to appear, and when it does I want you to take the action specified by response



So where you are going wrong is the command inside the block, you need to move the 'browser.button.click' or something similar inside the block. Your code would then end up looking something like this



require watir-webdriver
require watir-webdriver/extensions/alerts

browser = Watir::Browser.new
browser.goto page.html
browser.confirm(true) {browser.button(:value => 'click').click}


I changed your click action to be a bit more specific, identifying the button based on the value attribute in the HTML you provided. If you were sure it was always going to be the first button on the page you could change the last line to



browser.confirm(true) {browser.button.click}

[#87370] Friday, February 17, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;