Question

I tried watir wiki example to access modal window. But was getting Argument error. I am trying with watir 3 version.

    puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").exists?
    puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").title
    b.modal_dialog(:title, "showModalDialog Method Sample Target Page").close
    b = Watir::Browser.new()
    b.goto("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog.htm")
    b.button(:value,"Push To Create").click_no_wait

Error message

    C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contai
    ner.rb:60:in `modal_dialog': wrong number of arguments (2 for 0) (ArgumentError) from C:/webtest/popup.rb:29:in `<main>'

Can some one help how to access modal window using watir 3

Thanks

Was it helpful?

Solution

The error you're receiving is saying that you're supplying more arguments than are actually taken by the method.

I've never had call to use the actual modal methods within Watir, but after quick experimentation with the page you supplied I was able to interact with the modal using the following:

b.goto("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog.htm")
b.button(:id => "dCommand").click_no_wait
puts b.modal_dialog.text

In the above example I had it print out the text of the modal, but presumably any regular Watir command could be substituted.

It would appear that the requirement for an argument indicating which modal to interact with has been removed in Watir 3.0 or earlier (presumbaly because you can only interact with one?). I moved to Watir-webdriver as I primarily test in Firefox, so I'm not sure when this might have changed, but it does appear to be the case that it does not accept any arguments in 3.0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top