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)
Attribute Methods (8-9)
XPath Axes (10-17)
Sibling Axes (14-17)
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 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
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