Showing posts with label selenium web driver. Show all posts
Showing posts with label selenium web driver. Show all posts

Friday, 17 May 2019

Maven Libraries For Selenium Web Driver

To implement the any project using selenium web driver it is really important to have all the libraries set .So I will give you the POM dependencies for selenium web driver structure , you just need to copy paste it in your pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>0.1</groupId>
  <artifactId>POM1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
 
   <dependencies>
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
 
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.13</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
   
</dependency>
 
  </dependencies>
 
</project>
To Implement the page object model framework in selenium web driver ,do follow this tutorial

Find Elements Example In Selenium Web Driver

In this tutorial we will learn find Elements example in selenium web driver

findElements in selenium will return the list of web elements if match found for all the elements for a given selector. If no match found it will return NULL unlike findElement will return element not found exception.

So below example will show you how to use findElements and how to loop through the list of web elements .



import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class CountOfLinks {
 public static void main(String[] args) {
String path ="F:\\Automation_lib\\chromedriver_win32\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver",path);
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://www.icicibank.com/");
 
List<WebElement> els =driver.findElements(By.tagName("a"));
System.out.println("Number of links :"+els.size());
for(WebElement e :els) {
System.out.println(e.getAttribute("href")+"*****"+e.getText());
}
 
 }
}