Skip to content

pragmatictesters/selenium-location-strategies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selenium Location Strategies 🚀

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.

🔹 Project Overview

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

🌐 Live Demo Page

To practice locator strategies, visit the hosted demo page:
🔗 Demo Page on GitHub Pages

📂 Project Structure

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

🔧 Setup & Usage

1️⃣ Clone the Repository

git clone https://github.com/your-github-username/selenium-location-strategies.git
cd selenium-location-strategies

2️⃣ Run Local Demo Page

If you want to run demo-page.html locally:

cd docs
python -m http.server 8000

Then visit: http://localhost:8000/demo-page.html

3️⃣ Run Selenium Tests

  • Ensure Java & Maven are installed.
  • Update chromedriver path in BasicLocatorsTest.java.
  • Run tests using:
mvn test

📌 Locator Strategy Examples

Find by ID

WebElement username = driver.findElement(By.id("username"));

Find by Name

WebElement password = driver.findElement(By.name("password"));

Find by XPath

WebElement loginButton = driver.findElement(By.xpath("//button[@id='loginBtn']"));

Find by CSS Selector

WebElement link = driver.findElement(By.cssSelector("a.nav-link"));

📢 Contributing

  • 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 🚀

📜 License

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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages