- To find the only or first matching web element in case of multiple elements from the web page for the given locator.
- Returns only a single matching web element.
- No indexing as only one web element is returned.
- For no matching element, throw NoSuchElementException.
WebElement element = driver.findElement(By locator);
- To find all the matching web elements from the webpage for the given locator.
- Returns the collection of all matching web elements as a list.
- All web elements are indexed as a list starting from 0.
- For no matching element, no exception is thrown. Instead returns an empty list of size 0.
List<WebElement> elements = driver.findElements(By locator);
WebElement checkbox= driver.findElement(By.xpath(“//a[text()=’Checkbox Demo’]”));
List<WebElement> tableOptions=driver.findElements(By.xpath(“//a[contains(text(),’Table’)”);
WebElement element= driver.findElement(By.xpath(“//a[contains(text(),’Dynamic’)”);
It is created using the latest Selenium 4 features with Java, TestNG and Maven for Web-based automation.
This is the list of tools, being used in this framework:
- Apache Maven
- Java 8
- Selenium Cloud Grid - LambdaTest Platform
- TestNG Framework
- Import this project in Eclipse/IntelliJ as an “Existing Maven Project”.
- Go to test class file and Run a test case for your desired find element strategy.
- You can see the logs coming up on Console as your execution progresses.
- Since we are using RemoteWebDriver and executing on the Cloud Grid platform, LambdaTest, you can log in to the same and view detailed logs on the dashboard.