0
votes

I am trying to using watir in ruby, I am able open a browser, enter some values to a username/password form, but then I press enter, then I click the submit button (actually it is pressing an enter, it is easiler to code), it would pop up a new browser windows for our application, then I found I have no control to the new browser. What can I do?

In addition to my problem, the new browser window got no menubar, no toolbar, no navigation bar, thus I cannot open the IE developer toolbar to find the name of the element in the webpage in the new browser.

By the way, my app can only support IE.


I tried the attach method, but it does work:

C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb:302:

in `attach_browser_window': Unable to locate a window with title of (?-mix:New browser title) (Watir::Exception::NoMatchingWindowFoundException)

    from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb

:150:in `_attach_init'

    from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb

:144:in `attach' from test1.rb:36

3
1) Show Us Your Watir Code where you are trying the attach. Edit the posting above to add in the code, I think I know what you are doing wrong but can't be sure till I see the code. 2) Did you try using f12 to open the dev toolbar? - Chuck van der Linden

3 Answers

1
votes

Attach method is able to handle new window. http://rdoc.info/gems/watir/1.8.1/Watir/IE.attach

for example

browser = Watir::Browser.new
browser.text_field(:id,'username').set 'username')
browser.button(:index,1).click
# popped up the new window
popup = Watir::Browser.attach(:title,'Foobar')

If you will use only the popped up window, you can overwrite browser variable instead.

0
votes

You could try to authenticate like so:

examplehost.com/authentication?user=foo&password=bar

You could also try to remove "target" attribute (which is probably equal to "_blank") of that authentication form ( i'm pretty much sure you should be able to achive this with watir )

EDIT:

Also, there's this option:

ie2 = Watir::IE.attach(:title, ‘New Ie window, opened upon form submit’)

it can also attach by :url instead of :title

0
votes

ok, there's possibly this solution that might work:

b = Watir::Browser.start "http://yourpage"

b.execute_script("document.getElementById('your-image-id').onClick = function() {}")

so, the idea is to get that image and overwrite it's onclick event