This repository provides a comprehensive guide to locating elements in Selenium WebDriver using various strategies. It includes examples, best practices, and a demo page hosted on GitHub Pages for hands-on learning.
This project covers all possible Selenium location strategies, including:
- Basic Locators:
id
,name
,className
,tagName
- XPath & CSS Selectors: Absolute, Relative, Advanced
- Custom Locator Strategies
- Relative Locators (
above()
,below()
,near()
, etc.) - JavaScript-Based Locators
- FindAll, FindBy, FindBys
- Shadow DOM Handling
To practice locator strategies, visit the hosted demo page:
🔗 Demo Page on GitHub Pages
selenium-location-strategies/
│── docs/ # GitHub Pages hosting folder
│ ├── demo-page.html # Demo page for locators
│ ├── styles.css # Custom styles (branding)
│ ├── logo.png # Project branding logo (optional)
│── src/test/java/locators/ # Selenium test examples
│ ├── BasicLocatorsTest.java
│ ├── AdvancedLocatorsTest.java
│ ├── CustomStrategiesTest.java
│── README.md # Project documentation
git clone https://github.com/your-github-username/selenium-location-strategies.git
cd selenium-location-strategies
If you want to run demo-page.html
locally:
cd docs
python -m http.server 8000
Then visit: http://localhost:8000/demo-page.html
- Ensure Java & Maven are installed.
- Update
chromedriver
path inBasicLocatorsTest.java
. - Run tests using:
mvn test
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.name("password"));
WebElement loginButton = driver.findElement(By.xpath("//button[@id='loginBtn']"));
WebElement link = driver.findElement(By.cssSelector("a.nav-link"));
- Fork the repository 🍴
- Create a new branch:
git checkout -b feature-new-locator
- Commit your changes:
git commit -m "Added new locator strategy"
- Push and submit a PR 🚀
This project is licensed under the MIT License.
🔹 Stay tuned for more updates & advanced strategies!
📧 Contact: janesh@pragmatictesters.com
🌍 Pragmatic Testers - Helping Testers Master Automation!