Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open tabs using a Watir in ruby

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?

like image 347
Berg Dodson Avatar asked Aug 22 '14 17:08

Berg Dodson


People also ask

How do you select an element in Watir?

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.

Is Watir open source tool?

* Watir is a free Open Source tool with no costs charged on using this tool.

What is Watir Webdriver gem?

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.

What is Watir selenium?

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.


2 Answers

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

like image 94
Carldmitch Avatar answered Sep 28 '22 16:09

Carldmitch


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")')
like image 41
Astrit Shuli Avatar answered Sep 28 '22 16:09

Astrit Shuli