Non-Unique identification of elements using the contains() method

Posted 8 months ago by David

Post a topic
Un Answered
David Rumley
David Admin

There are times when you may want to fashion a locator that identifies a group of objects/elements on the screen.  Consider the scenario where you want your test to iterate over all of the similar elements on the screen and perform some action or verification of each.

A simple example of this (using our demo site: Bike Shop https://bikeshop.alchemytesting.com) is the verification of product category labels on the various pages.  In other words make sure on the Bicycles page, all the products have the category "Bicycles".  Or, on the Accessories page, all the products have the category "Accessories".


To do this, Use the Alchemy browser in "Inspector mode"


You can formulate, type in, and test an xpath locator in the Descriptor field (green box above).  One handy xpath method for accomplishing this is: contains().


The syntax for locating elements through XPath- Using contains() method can be written as: 

  1. //<HTML tag>[contains(@attribute_name,'attribute_value')]  
  2. //*[contains(@attribute_name,'attribute_value')] 


For example: on the Bicycles page if you use the descriptor:

//SPAN[contains(@class,'ast-woo-product-category')]

You will identify all the SPAN tags on the page with the class:"ast-woo-product-category".


Now, you can add this Locator to your Site in Alchemy.  Then use that locator to iterate over the identified elements.  See other Topics, KB articles or videos for looping or iterating over elements.


1 Votes


0 Comments

Login or Sign up to post a comment

© Orasi Software, Inc. | All Rights Reserved.