How can I open more than one browser using my code-watir, for example via a while
loop from 0 to 10?
Here is my code:
require 'watir-webdriver'
require 'headless'
class Page
@headless = Headless.new
@headless.start
@browser = Watir::Browser.start 'bit.ly/***'
def self.get_connection
puts "Browser started"
puts @browser.title
@browser.driver.manage.timeouts.implicit_wait = 3 #3 seconds
@browser.select_list(:name => 'ctl00$tresc$111').select_value('6')
puts "Selected country"
@browser.select_list(:name => 'ctl00$tresc$222').wait_until_present
@browser.select_list(:name => 'ctl00$tresc$333').select_value('95')
puts "Selected city"
end
def self.close_connection
@browser.close
@headless.destroy
end
end
Page.get_connection
Page.close_connection
But how to do something like this?
while i < 10
Page.get_connection
end
This should open ten browsers:
10.times {Watir::Browser.new}
If you want to use the browsers later, you can put them in a hash:
browsers = {}
(0..9).each {|i| browsers[i] = Watir::Browser.new}
browsers[0].goto "google.com"
browsers[1].goto "yahoo.com"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With