Forum: Ruby windows.count in WATIR

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-08 11:07

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

require 'watir-webdriver' :chrome

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

I was actually using the below code #=> [#, #] #=> true
browser.window(:title => "foo").use
browser.window(:url => /bar/).use { ...code... }


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:

=> #<Watir::Window:0x4f93c05e located=true>
irb(main):018:0> b.title
=> "The Internet"
=> #<Watir::Window:0x..fd757b80 located=true>
irb(main):020:0> b.title
=> ""

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

This prints the title of the first tab,

if I write

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

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

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

require 'watir-webdriver' :chrome
browser.goto "","Go to Way2SMS now").click
browser.text_field(:id, "username").set("MOBILE NUMBER HERE")
browser.text_field(:id, "password").set("PASSWORD")
browser.button(:value,"Send Free SMS").click, "Future SMS").click

browser.text_field(:id, "mobile").set("22222")
browser.area(:id, "message").set("m")

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

1 require 'watir-webdriver'
2 :chrome
3 browser.goto ""
4,"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, "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
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

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.
This topic is locked and can not be replied to.