DZone
DevOps Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > DevOps Zone > Detecting Elements With Xpath in Katalon Studio

Detecting Elements With Xpath in Katalon Studio

Learn how to detect UI elements of the application under test in the Katalon Studio framework for test automation in this tutorial.

Oliver Howard user avatar by
Oliver Howard
·
Oct. 14, 17 · DevOps Zone · Tutorial
Like (7)
Save
Tweet
15.81K Views

Join the DZone community and get the full member experience.

Join For Free

Detecting UI elements of the application under test (AUT) is crucial for automation testing since they are the main objects in test cases and test scripts. However, identifying them manually requires much time and experience in HTML. This task becomes even more challenging for objects that could not be identified by their common attributes or are located deep within another element (nested objects). This article shows you how Katalon Studio provides supports to deal with such cases.

Read more tutorials in the Advanced section.

What Is Xpath?

XPath expression is a mechanism for navigating through and selecting a node in an XML document. It can also be used to locate an HTML element.

For example, the Download link in the script below is an element nested in another.

<div class="container">
 <div class="navbar-collapse navbar-right" aria-expanded="true">
   <div class = "nav-bar-decorated"
     <ul class="nav navbar-nav">
       <Li>
         <a class="pbtn-download" href="#katalon-download">Download</a> <!-- Deeply nested element  -->
       </li>
   </div>
 </div>
</div>

Issue in Identifying Nested Elements

It is difficult to identify a nested element, such as the <a> element in the script above. In order to define the XPath manually, we need to have solid knowledge about DOM structure of the webpage.

How to Identify Nested Elements?

Identifying XPath is an effective way to find nested elements which can’t be identified by common properties such as ID, Name, or Class. There are two ways to find XPath:

  • Detect XPath by other tools: Web browsers usually have Adds-on support users to identify XPath. However, It can be a challenge since it depends on a lot of the tools.
  • Detect XPath by Katalon Studio: Katalon Studio can generate and optimize XPath for HTML elements, regardless of how deeply nested they are. You can use these XPaths to identify elements without having to search through the DOM tree.

The example below illustrates how Katalon Studio generates and optimizes XPath automatically when you spy on the Sign up now object (a nested object).

detecting elements with Xpath by Katalon Studio

Deal With Dynamically Changing Elements

One of the challenging and time-consuming tasks in test automation is to modify test scripts when the AUT is changed, especially in the early stages of software development. Developers may change identifiers and elements quite often from one build to another. In addition, during the execution, the AUT’s elements may change dynamically.

To deal with these challenges, automation testers should not set fixed XPaths for elements in test cases, but instead, scripting XPaths dynamically based on certain patterns. Katalon Studio supports all Xpath Axes, such as

  • following-sibling
  • preceding-sibling
  • contains
  • descendant
  • starts-with

Here are a few examples:

Xpath value Description
.//h2[text()=’Make Appointment’] Locate the h2 tag element that has text matching exactly “Make Appointment”
//*[contains(text(),’Login’)] Locate any element that contains the text “Login”
//a[starts-with(@id=’LoginPanel’)] Locate the a tag element that has the ID starting with “LoginPanel”

For more information on XPath Axes, refer to XPath Axes from www.w3schools.com.

Element XPath Katalon Studio

Published at DZone with permission of Oliver Howard. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Evolution of Configuration Management: IaC vs. GitOps
  • Evolving Domain-Specific Languages
  • 6 Things Startups Can Do to Avoid Tech Debt
  • What Is Lean Software Development

Comments

DevOps Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo