Forum: Ruby windows.count in WATIR

Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-08 11:07
hi,

 I am automating chrome browsers and writing the following code to find
the windows count

require 'watir-webdriver'
browser=Watir::Browser.new :chrome
puts browser.windows.count

But no matter how many browser opened, it always return 1. Can you any
one give the solution for me why it always return 1?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-08 19:22
Probably because you're opening new browsers, not windows within the
current browser session.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-08 19:42
Hi,

I was actually using the below code

browser.windows #=> [#, #]
browser.windows.first.current? #=> true
browser.windows.last.use
browser.windows.first.close
browser.window(:title => "foo").use
browser.window(:url => /bar/).use { ...code... }


browser.driver.switch_to.window(browser.driver.window_handles[0])

To attach a Chrome browser, But since control is always in the first
browser as I explained in my first comment, I couldn't able to attach
the first browser. Is there any solution to attach the first browser?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-09 01:17
I can access multiple Chrome tabs using the "windows" method:

irb(main):017:0> b.windows.first.use
=> #<Watir::Window:0x4f93c05e located=true>
irb(main):018:0> b.title
=> "The Internet"
irb(main):019:0> b.windows.last.use
=> #<Watir::Window:0x..fd757b80 located=true>
irb(main):020:0> b.title
=> "http://the-internet.herokuapp.com/windows/new"
irb(main):021:0>

I can still do the same when they're different windows rather than tabs.
No problem controlling each in turn.

What error message do you get?
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-11 11:35
hi Joel,

I guess you are wrong, It's shifting between tabs, it's not swifting
between windows, I opened  a single browser and three tabs,

And I started to use your code to print the title, If I write
b.windows.first.use
b.title

This prints the title of the first tab,

if I write

b.windows.last.use
b.title

Then it prints the title of the last tab.

Can you verify yours once again and tell me whether it's shifting
between the windows or tabs please?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-11 21:05
As I said before, I can switch between them whether they're windows or
tabs. Chromedriver doesn't differentiate.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-12 05:25
hi,

what is the code you are writing for shifting between tabs? and What is
the code you are writing for shifting between windows?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-12 21:05
I showed the code above. I used it with tabs, then dragged the tabs out
into separate windows and ran the same code again.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-15 17:21
Hi,

Thank you Joel, I have another doubt while I am automating Way2sms.com
for future sms, Please have a look at my code below

PART1
________________
require 'watir-webdriver'
browser=Watir::Browser.new :chrome
browser.goto "http://site22.way2sms.com/content/prehome.html"
browser.link(:text,"Go to Way2SMS now").click
browser.text_field(:id, "username").set("MOBILE NUMBER HERE")
browser.text_field(:id, "password").set("PASSWORD")
browser.button(:value,"Login").click
browser.button(:value,"Skip").click
browser.button(:value,"Send Free SMS").click
browser.link(:text, "Future SMS").click

PART 2
___________________
browser.text_field(:id, "mobile").set("22222")
browser.text_field(:id,'sdate').set("15/08/2014")
browser.text_field(:id,'stime').set("20:00")
browser.area(:id, "message").set("m")
browser.button(:value,"Sending..").click

I have separated my code as part1 and part2, part1 is working fine, but
part2 is not working, because this seems to be there is another html
file within the first html file, Can you please tell me how can I
automate such page?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-15 20:55
Show me the page html, and show exactly which lines fails and what the
error message is.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-16 21:03
hi

1 require 'watir-webdriver'
2 browser=Watir::Browser.new :chrome
3 browser.goto "http://site22.way2sms.com/content/prehome.html"
4 browser.link(:text,"Go to Way2SMS now").click
5 browser.text_field(:id, "username").set("MOBILE NUMBER HERE")
6 browser.text_field(:id, "password").set("PASSWORD")
7 browser.button(:value,"Login").click
8 browser.button(:value,"Skip").click
9 browser.button(:value,"Send Free SMS").click
10 browser.link(:text, "Future SMS").click

11 browser.text_field(:id, "mobile").set("22222")
12 browser.text_field(:id,'sdate').set("15/08/2014")
13 browser.text_field(:id,'stime').set("20:00")
14 browser.area(:id, "message").set("m")
15 browser.button(:value,"Sending..").click

HI, Line number 11 is not working, the page which would be arrived when
program meet line number 11.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-18 12:39
hi Joel,

I shifted to work in Ruby 2.0, Hope you are also working there, Can you
please tell me whether you can create xml file successfully or not? I am
using  "MiniTest::Unit::TestCase"  to create result of test, But I don't
know what ci_reporter has to be installed for this? Can you please guide
me?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-23 12:07
I've never used minitest, maybe someone else could help with that.

Your HTML is incomplete, the link "Future SMS" triggers the JS function
"loadSMSPage('futureSMS')", which does not appear in the HTML you
provided.

The best way to find out what element you're looking for is to load up
IRB, start watir-webdriver, navigate to your target page, and use
Firefox's "inspect element" in combination with the element "flash"
command to locate each layer until you reach your target element. You'll
probably find that it's in an iframe or something like that which
requires specific referencing in order to access any sub-elements.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-23 12:31
hi Joel,

Thank you.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.