Selenium WebDriver

Day 24: Advanced XPath Practice & Assignments

Advanced XPath practice with complex scenarios, real-world applications, and comprehensive assignments

Today's Learning Objectives

Advanced XPath Mastery

  • • Complex XPath combinations and chaining
  • • Dynamic element handling strategies
  • • Performance optimization techniques
  • • Cross-browser compatibility considerations

Real-World Applications

  • • E-commerce website automation
  • • Form handling and validation
  • • Data extraction from complex tables
  • • Multi-level navigation scenarios

Complete XPath Techniques Mastery

Basic Methods (1-7)

1. Single attribute
2. AND operator
3. OR operator
4. text() method
5. contains() with text()
6. starts-with() with text()
7. normalize-space()

Attribute Methods (8-9)

8. contains() with attribute
9. starts-with() with attribute

XPath Axes (10-17)

10. child::
11. descendant::
12. parent::
13. ancestor::

Sibling Axes (14-17)

14. following-sibling::
15. preceding-sibling::
16. following::
17. preceding::

Advanced XPath Scenarios

Complex Table Navigation

Multi-Column Data Extraction

Get employee salary by name:

//td[text()='John Doe']/following-sibling::td[3]

Get all employees in specific department:

//td[text()='Engineering']/preceding-sibling::td[1]

Dynamic Table Handling

Find row by multiple criteria:

//tr[td[text()='Active'] and td[contains(text(),'Manager')]]

Get nth column of specific row:

//tr[td[text()='John']]/td[position()=4]

Form Element Relationships

Label-Input Associations

Input field by label text:

//label[text()='Email Address']/following-sibling::input

Complex form navigation:

//label[contains(text(),'Password')]/parent::div/following-sibling::div/input

Checkbox and Radio Groups

Select checkbox by label:

//label[text()='I agree to terms']/preceding-sibling::input[@type='checkbox']

Radio button in group:

//input[@name='gender' and @value='female']

XPath Performance Optimization

⚡ Fast XPath Strategies

Use Unique Attributes

✅ Good: //input[@id='username']

❌ Slow: //div//div//input[@type='text']

Minimize Depth

✅ Good: //form//input[@name='email']

❌ Slow: /html/body/div/div/form/div/input

Use Specific Tags

✅ Good: //button[text()='Submit']

❌ Slow: //*[text()='Submit']

🐌 Avoid These Patterns

Wildcard Overuse

❌ //*[@class='btn']//*[@type='submit']

Deep Nesting

❌ //div/div/div/div/div/input

Position-based Selectors

❌ //tr[5]/td[3]

Complex Text Matching

❌ //*[contains(text(),'very long text with spaces')]

Advanced Practice Assignments

Comprehensive XPath Assignments

Complete these advanced assignments to master complex XPath scenarios and real-world automation challenges.

Assignment 2 (Advanced)

Complex scenarios with dynamic elements, table navigation, and form automation.

Assignment materials available in course resources

Practice Document

Editable document with practice exercises and solution templates.

📝 Assignment Available in Course Materials

Assignment Focus Areas

  • • E-commerce product selection
  • • Multi-step form completion
  • • Dynamic dropdown handling
  • • Table data validation
  • • Cross-browser compatibility
  • • Performance optimization
  • • Error handling scenarios
  • • Complex navigation patterns

Knowledge Check

Question 1 of 5

Which XPath expression is most efficient for locating a unique element?

Key Points Summary

XPath Mastery

  • • Master all 17 XPath techniques for complete coverage
  • • Combine multiple methods for complex scenarios
  • • Optimize for performance using specific selectors
  • • Handle dynamic elements with flexible strategies

Best Practices

  • • Use unique attributes when available (ID, name)
  • • Avoid wildcards and deep nesting
  • • Test XPath expressions in browser console
  • • Consider maintainability and readability

SDET Mastery

Master Test Automation

Home
CurriculumPracticeQ&ACheatsheet
🍵Buy me a Chai

Automation Testing Course

Comprehensive course covering Manual Testing, Java Programming, and Selenium WebDriver

🍵Buy me a Chai
Privacy Policy•GitHub
© 2024 Automation Testing Course. All rights reserved.