I'm trying to create additional tabs in Firefox using Watir webdriver. However, I'm not having much luck
After opening the browser:
require 'watir-webdriver'
b =Watir::Browser.new
I want to open up tabs but have been unable to figure out how to access the Open a New Tab button on the browser. How could I create a new tab then?
Elements are located by creating a Selector Hash, which Watir translates into the potentially complicated information the driver needs to know to identify the element. The special cases will be highlighted below, but Watir Locators: Accept String values for exact matching. Accept RegExp values for partial matching.
* Watir is a free Open Source tool with no costs charged on using this tool.
Watir (Web Application Testing in Ruby), pronounced as "Water" is an open source tool developed using Ruby which helps in automating web application no matter which language the application is written. The browsers supported are Internet Explorer, Firefox, Chrome, Safari, and Edge.
Watir is an open-source web application testing framework that is designed to make writing Selenium tests simple and efficient. Built on Selenium's Ruby language bindings, Watir is able to drive the browser in the same way humans do.
As already mentioned Selenium doesn't explicitly support opening of tabs, however there are 'workarounds' such as...
require 'watir-webdriver'
browser = Watir::Browser.new :ff
browser.goto 'http://the-internet.herokuapp.com'
browser.link(:text, 'A/B Testing').click(:command, :shift)
browser.windows.last.use
This will open the link in a new tab (on a mac) and focus it
You can use javascript :
require 'watir' # Crawler
browser = Watir::Browser.new :chrome #or firefox in your case
browser.goto 'http://example.com'
browser.execute_script('window.open("http://example1.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