Skip to content
AS

Admira Suljic

1 article

April 15, 2020

Chaining locators in Protractor

QA/Test Automation

Chaining locators in Protractor

Concept of Chain Locators    The essence of end-to-end website testing is finding DOM objects, dealing with them and getting details about the application's current state. Protractor is one of the most commonly used frameworks for AngularJS applications where locators are used as instructions to show Protractor how to locate the element. Finding the elements is not a significant challenge since there are many ways to do it, for example, by.css, by.id, by.name, by.model,etc. Using a single locator to find: - an element: element(by.css('.myclass’));  - a list of elements: element.all(by.css('.myclass’)); Considering that for some subelements of the website we are not always able to identify locators as mentioned above, we have to use the Concept of Chain Locators. This means that you can chain multiple locators to select an element in a complex application, such as: element(by.css('.myclass')).element(by.tagName('tag-within-css')); Chain Locators to Identify Child Elements This is an overview of a Protractor test in Jasmine, where we have an example of using a chain locator to reach a child element. describe('Chain locators', function() { it('Open Angular js website',function() { browser.get('http://juliemr.github.io/protractor-demo/'); element(by.model("first")).sendKeys("3"); element(by.model("second")).sendKeys("5"); element(by.id("gobutton")).click(); element(by.repeater("resultinmemory")).element(by.css("td:nth-child(3)")).getText().then(function(text) { console.log(text); }); }); });   "Chaining locators in Protractor" Tech Bite was brought to you by Admira Suljić, 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)