This repository contains code examples demonstrating how to locate web elements using Selenium WebDriver in Java. These code snippets serve as a reference for beginners learning Selenium automation.
Ensure you have Java and Selenium WebDriver configured in your development environment.
- Java Development Kit (JDK)
- Selenium WebDriver (add the Selenium dependency to your project)
Clone the repository to your local machine using:
git clone https://github.com/stsharin/locating-elements-selenium.git
Navigate to the src
directory to find code snippets showcasing different methods of locating web elements using Selenium WebDriver in Java.
Examples
browser.findElement(By.tagName("h1"));
browser.findElement(By.id("fname"));
browser.findElement(By.name("lname"));
browser.findElement(By.xpath("//select[@id=\"dropdown-class-example\"]"));
browser.findElement(By.cssSelector("input[value=\"radio2\"]"));
browser.findElement(By.linkText("Open Tab"));
browser.findElement(By.partialLinkText("Free Access to InterviewQues"));
browser.findElement(By.className("ui-autocomplete-input"));
Contributions are welcome! If you have additional examples or improvements, feel free to fork this repository and create a pull request.
This project is licensed under the MIT License.