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?
Probably because you’re opening new browsers, not windows within the
current browser session.
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?
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?
I can access multiple Chrome tabs using the “windows” method:
irb(main):017:0> b.windows.first.use
=> #<Watir:0x4f93c05e located=true>
irb(main):018:0> b.title
=> “The Internet”
irb(main):019:0> b.windows.last.use
=> #<Watir:0x…fd757b80 located=true>
irb(main):020:0> b.title
=> “New Window”
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?
As I said before, I can switch between them whether they’re windows or
tabs. Chromedriver doesn’t differentiate.
hi,
what is the code you are writing for shifting between tabs? and What is
the code you are writing for shifting between windows?
I showed the code above. I used it with tabs, then dragged the tabs out
into separate windows and ran the same code again.
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?
Show me the page html, and show exactly which lines fails and what the
error message is.
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?
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.
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.