Skip to content
CodeKruPro

Find buttons with basic XPath

Automation taskEasyAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

"Write an XPath for the button with id leftClick, and one for any disabled button." A relative XPath starts with //, which means "anywhere in the page", and filters with a condition in square brackets, such as //button[@id='leftClick'].

XPath - Basics

Video walkthrough

Watch on YouTube

XPath Basics

XPath is a powerful language for navigating XML/HTML documents. Key patterns:

  • //tag - find tag anywhere in document
  • //tag[@attr='value'] - find tag with attribute value
  • //tag[text()='value'] - find tag with exact text

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Find the button using XPath //button[@id='leftClick']
  3. Print its text
  4. Find the disabled button using XPath //button[@disabled]
  5. Print its text

Expected output:

Button 1: Left click on me
Button 2: Disabled button
Read full tutorial on Codekru