In this video will see how to count any specific type of webElements (e.g no. of hyperlinks, input boxes, images etc). In other words we can get how many times any webelement occurred on any given point of time. We will also see how to print the text of webelements.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Code:
public class TagCountOnWebPage {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "directory path of chrome driver exe\\chromedriver.exe");
ChromeOptions op = new ChromeOptions();
op.setBinary("directory path of chrome exe\\chrome.exe");
op.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver(op);
driver.get("https://programmerworld.co/");
List <WebElement > linkElements = driver.findElements(By.tagName("a"));
System.out.println("Total no. of hyperlinks"+linkElements.size());
for(WebElement el:linkElements)
{
System.out.println(el.getText());
}
}
}
Excerpt:
The provided content is a code snippet and a YouTube link for a video tutorial. The code demonstrates how to count specific types of web elements like hyperlinks on a webpage using Selenium WebDriver in Java. It also shows how to print the text of those web elements. The YouTube link leads to a tutorial demonstrating the process explained in the code. For additional inquiries or feedback, the contact information at programmerworld.co can be used.