Skip to content
AS

Azra Sirucic

1 article

April 15, 2020

Locating Elements in Watir

QA/Test Automation

Locating Elements in Watir

Locating Elements (Watir)  Watir (Web Application Testing in Ruby) is an open-source Ruby library for automating web browsers. It interacts with different browsers (Firefox, Chrome, Safari…) the same way people do: clicking buttons, links, populating forms and validating text. But what about locating Elements in Watir? Watir allows users to locate elements in many ways which represents one of its most important features. With Watir, the user can locate any element by its text, not just links. No more XPath!  Directly using powerful :css & :xpath selectors are supported in Watir, but Watir’s goal is to minimize the need to rely on these selectors, because for example, XPath can be difficult to read. Standard Watir Locators ID & Index browser.div(id: ‘user_id’) #When combined with other locators, index is the last filter to be applied browser.div(index: 1) Name & Class Name browser.text_field(name: ‘new_user_email’) #This is for locating with a single class only browser.text_field(class: ‘name’) Tag Name browser.element(tag_name: ‘div’) #You can use browser.element but it is highly recommended to leverage this locator by using the element’s associated method: browser.div Text & Visible Text #Text evaluates what is in the DOM and Visible Text evaluates what the user can see on the page browser.button(text: ‘Button’) browser.button(visible_text: ‘Start’) "Locating Elements in Watir" Tech Bite was brought to you by Azra Siručić, Junior Test Engineer at Atlantbh. (more…)

Ready to Achieve More?

We’ll help you reach your goals quickly with an easy and straightforward process to kick off our collaboration. Here’s what happens next.

STEP 1

Discovery Call

Let’s chat to understand your company, project needs, and answer any questions along the way.

STEP 2

Free Consultation

Work closely with our experts to explore the right solutions for your business.

STEP 3

Collaboration Proposal

We'll recommend the best strategy for your goals, ensuring you get the most from our expertise.

STEP 4

30-Day Cancellation
Policy Contract

Spoiler: It’s Never Been Used

Enjoy peace of mind while we deliver excellence from day one—our track record speaks for itself.

Services you're interested in (Optional)