head, tail, more & less Commands in Unix/Linux



head : to display specified number of lines from top of the file.

--------

head cities.txt


* Display 10 lines from top of the file.

* 10 is the dfault value for head command


head -n 15 cities.txt  (or)  head -15 cities.txt


head -n 5 cities.txt  



tail : to display specified number of lines from bottom of the file.

----------------

tail cities.txt


* Display  last 10 lines from the file.

* 10 is the dfault value for tail command


tail -n 15 cities.txt  (or)  tail -15 cities.txt


tail -n 5 cities.txt   



Display the lines from 10 to 15 ?

head -15 cities.txt | tail -6


Display the lines from 20 to 30 ?

head -30 cities.txt | tail -11


ls - l   Display List of files and directories


ls -l | head -5   Display Top 5 files and directories

ls -l | tail -5   Display Top 5 files and directories



more : Display content page by page.(Next page - space, Next line - Enter,  q- Command prompt)

--------------

more cities.txt


more : Display content page by page in both directions means next page or to previos page

Next page - space, Next line - Enter,  q- Command prompt)

--------------

more cities.txt

ls -l | more

ls -l | less

touch, pwd & ls Commands in Unix/Linux

 



ls : List Files 


ls -l   : shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.


ls -a   : view hidden files

touch .myfile.txt

ls -a

ls -l -a : detailed listing files along with hiddwn files

ls -F : will add the ‘/’ Character at the end each directory.

ls -r : display files and directories in reverse order.


ls -R : displays directories along with sub subdirectories


ls -lS : displays file size in order, will display big in size first.


ls -l Documents : list files under directory Documents


wild card characters

--------

? Single character

* Multiple characters

[ ] Range of values


ls ?.*

Output: a.doc  b.doc  c.doc  x.txt  y.txt


ls ?.doc

Output: a.doc  b.doc  c.doc

ls ?.txt

Output: x.txt  y.txt

ls a* Displays files which are starting with 'a'

Output: abc.doc  a.doc


Range(Displays files starting with a to z)

ls [a-z]*.*

ls [a-c]*.*

ls [a-z]*.txt


rm ?.* Removes the files with single character

rm *.txt Removes the files with extension txt

rm *.doc Removes the files with extension txt

Unix/Linux File and Directory Commands

 



cat

Creating the new file

Display content of the file

Concatenating more than one file

Appending data to the existing file

cp - Copy contents from a file to another file(source to destination)

mv

Renaming a file(changing name of the file)

Renaming a directory

Moves files from one directory to another directory

rm - Delete/remove a file or directory (only if directory is empty).



mkdir - create directories and subdirectories.

mkdir testdir

create multiple directories at one time:

 mkdir testdir1 testdir2 testdir3

create several subdirectories at one time:

 mkdir -p world/countries/states

-------------------------------------------------------------------

cd - changing/closing directory

cd ..    : go back to one level

cd /testdir1/testdir2/testdir3 → changing directory

pwd  :  it prints present directory

cd ~     Move to users home directory from anywhere.

------------------------------------------------------------------

rmdir - Remove the directory if it is empty (works only if directory empty)


rmdir world      // error

rm -r world

rmdir testdir1 testdir2 testdir3



Manual & Automation Testing Free Video Tutorials | YouTube Playlists


** How to Prepare for a QA Test Automation Interview

https://youtu.be/gJZpjl_SQ00

** Project based FAQ's & Resume Preparation

https://www.youtube.com/watch?v=Vn8Vn37G2Pc

Selenium FAQ’S (8 Parts)

https://www.youtube.com/watch?v=APRVsl01AZI&list=PLUDwpEzHYYLtFHGMSyucq8IP3vcsvpUTi

Selenium Locators

https://www.youtube.com/watch?v=HBOdscUwUnc&list=PLUDwpEzHYYLut2OnS4GlY7fiSAabRmsz3

Selenium Grid:

https://www.youtube.com/watch?v=ewUI1p-tZ64&t=385s

ApachePOI API Advanced( for Selenium)

https://www.youtube.com/watch?v=ipjl49Hgsg8&list=PLUDwpEzHYYLsN1kpIjOyYW6j_GLgOyA07

Selenium4 New Features

https://www.youtube.com/playlist?list=PLUDwpEzHYYLtW68M8fSawlFvsG0YX82Tx

Git & Github advanced

https://www.youtube.com/watch?v=HCeBd5GKNO8

Java Collections

https://www.youtube.com/watch?v=hKhlkx_6HeI&list=PLUDwpEzHYYLu9-xrx5ykNH8wmN1C1qClk

Java Lambda Expressions

https://www.youtube.com/watch?v=MMruoVq6160&list=PLUDwpEzHYYLtNoZUJaRJfCktwjVtOwIk3

Java Streams

https://www.youtube.com/watch?v=33JrZGtKOEE&list=PLUDwpEzHYYLvTPVqVIt7tlBohABLo4gyg

Java Coding FAQ’s

https://www.youtube.com/watch?v=3vbizK6KzaU&list=PLUDwpEzHYYLtgkXK6YaZ4I2XcsjMqIaEa

Docker

https://www.youtube.com/watch?v=AQbSmki24Xw&list=PLUDwpEzHYYLtpm24ojHwubwmMNQildHBc

Protractor

https://www.youtube.com/watch?v=LzrNtbKANCg&list=PLUDwpEzHYYLt9nBh8fMrJMt2PCHnWCqN1

Cucumber

https://www.youtube.com/watch?v=aFlAXLSHbCg&list=PLUDwpEzHYYLuOleK8iPl6kc2UbXGvllBY

Miscellaneous Topics in Selenium

Ajax/Stale Element Exception: https://www.youtube.com/watch?v=m558zwIM-bU

Robot Class API: https://www.youtube.com/watch?v=jz7MgzNsepI&t=757s

Handle Authentication Popup: https://www.youtube.com/watch?v=cj8z9_c6ejo&t=525s

Automate QR Code: https://www.youtube.com/watch?v=5Ihbu93zxIU&t=693s

Automate Bar Codes: https://www.youtube.com/watch?v=M2cypkjI93c&t=70s

Check Bitmaps/Images: https://www.youtube.com/watch?v=1CBS1AQy6zo&t=717s

Headless browser testing: https://www.youtube.com/watch?v=WqIAcYXaIZA&t=1s

Java script Executor in Selenium: https://www.youtube.com/watch?v=P6LBk_qzISg&t=2625s

DB testing in Selenium (JDBC): https://www.youtube.com/watch?v=Sw3eqsKvfCM

Checking Broken links in page: https://www.youtube.com/watch?v=E0gvFxM6qTw

Use Java HashMap in Selenium: 

https://www.youtube.com/watch?v=x7AIIVFgQVw

Working with Cookies (part1): https://www.youtube.com/watch?v=TjLU9Iq9AeE

Working with Cookies (part2): https://www.youtube.com/watch?v=cv5A4yO8QDo

AutoIT (Part1): https://www.youtube.com/watch?v=wI6hUWcu2Uk

AutoIT (Part2): https://www.youtube.com/watch?v=j22WqyW6PJo

API Testing using Postman

https://www.youtube.com/watch?v=95NBave0W_k&list=PLUDwpEzHYYLt3kLIHDLVjdnmJw7BDvVdE

API Testing using SOAPUI

https://www.youtube.com/watch?v=4Od5hMd-EPM&list=PLUDwpEzHYYLugXkSaNTuQ4J3HFXVWNUf-

API Testing using RestAssured

https://www.youtube.com/watch?v=n3UITFRJ9KU&list=PLUDwpEzHYYLskkglxoXd0L6DKu4uOfh-m

JMeter Performance Testing

https://www.youtube.com/watch?v=817zU_bXh9Y&list=PLUDwpEzHYYLs33uFHeIJo-6eU92IoiMZ7

Manual Testing Full Course

https://www.youtube.com/watch?v=QJqNYhiHysM&list=PLUDwpEzHYYLuMijnpSMKtv14sUuJLlgt_

Manual Testing Project

https://www.youtube.com/watch?v=7KvTEW243rg&list=PLUDwpEzHYYLu4ey2FpbMuZOPZ2kKb3o5v

SQL Videos:

https://www.youtube.com/playlist?list=PLUDwpEzHYYLt0aRs7gvyEEviMp_CoTO3q

Manual Testing + Jira Videos:

 https://www.youtube.com/watch?v=Wb-g7tPO2Gw&list=PLUDwpEzHYYLsMt3L4MnvmsL_DhxUNTW6J

Apache POI Tutorials for Selenium Automation


 
Apache POI Tutorial Part1 - How To Read Data From Excel 


Apache POI Tutorial Part2 - How To Write Data on Excel 


Apache POI Tutorial Part3 - How To Read Data from Formula Cell in Excel Sheet


Apache POI Tutorial Part4 - How To Write Formula Cell in Excel Sheet



Apache POI Tutorial Part5 - How To Read Data from Password Protected Excel 


Apache POI Tutorial Part6 - How To Fill Background and Foreground Colors into Cell


Apache POI Tutorial Part7 - MS-Excel with Java Hash Map



Apache POI Tutorial Part8 - How To Read Data from Database and Write into Excel


Apache POI Tutorial Part9 - How To Read Data from Excel and Write into Database Table 


Apache POI Tutorial Part10 - Data Driven Testing in Selenium | TestNG DataProvider and Excel



Apache POI Tutorial Part11 - How To Write WebTable data into Excel Sheet in Selenium (Web Scraping)


Apache POI Tutorial Part12 - How to work with Date Cells in the MS-Excel




Code Snippets:
Github Link : https://bit.ly/3nQsN9L


How to use Java Collections, Lambda Expressions & Streams in Selenium Automation


Example1:

/1) Find Number of Links in Page

2) Print Link Texts from all the links

3) Check how many links does not have href attribute(broken links)

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Demo1 {

public static void main(String[] args) {

WebDriverManager.chromedriver().setup();

WebDriver driver = new ChromeDriver();

driver.get("http://demowebshop.tricentis.com/");

List<WebElement> links = driver.findElements(By.tagName("a")); // Here is List is collection

System.out.println(links.size());

//Printing linkTexts using for..each loop(Before Java8)

for (WebElement link : links) {

System.out.println(link.getText());

}

//Printing linkTexts using lambda expression

links.forEach(link -> System.out.println(link.getText()));

//Processing elements using stream -> filter

long workingLinks=links.stream().filter(link->link.getAttribute("href")!=null).count();

System.out.println("Working link:"+workingLinks);

driver.close();

}

}


Example2:

import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;

public class Demo2 {

public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

driver.get("https://www.amazon.in/");
driver.switchTo().newWindow(WindowType.TAB);
driver.get("https://www.flipkart.com/");//driver.navigate().to("https://www.flipkart.com/");
Set<String>windowIds=driver.getWindowHandles(); // Here using Set collection

for(String windowid:windowIds)
{
driver.switchTo().window(windowid);
System.out.println(driver.getTitle()); //System.out.println(driver.getCurrentUrl());
}
//Print the titles using lambda expression
windowIds.forEach(winid ->      System.out.println(driver.switchTo().window(winid).getTitle()));
driver.quit();
}

}


Example3:
1) Display books in sorted order(A-Z) using DropDown
2) Capture all the products in to a list (Original list)
3) Sort products ( using stream & lamda)then capture in to another list (Sorted list)
4) Compare Original list with Sorted list 


import java.util.List;
import java.util.stream.Collectors;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import io.github.bonigarcia.wdm.WebDriverManager;

public class Demo3 {

public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

driver.get("http://demowebshop.tricentis.com/");
driver.findElement(By.xpath("//ul[@class='top-menu']//a[normalize-space()='Books']")).click();
Select sortbydrp=new Select(driver.findElement(By.id("products-orderby")));
sortbydrp.selectByVisibleText("Name: A to Z");
List<WebElement> product_items=driver.findElements(By.xpath("//h2[@class='product-title']"));
List<String> beforesort=product_items.stream().map(item->item.getText()).collect(Collectors.toList());
List<String> aftersort=product_items.stream().map(item->item.getText()).sorted().collect(Collectors.toList());
System.out.println(beforesort);
System.out.println(aftersort);
if (beforesort.equals(aftersort)) 
            System.out.println("products displayed in Sorted Order"); 
        else
        System.out.println("products displayed in NOT Sorted Order"); 
driver.quit();
}

}


---------------------------------------------------------
Example4:

 1) capture all product titles & prices in hashmap
 2) find product whose price is greater than 800
 3) Sort products based on prices

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

public class Demo4 {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C://Drivers//chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver(); 
driver.get("http://demowebshop.tricentis.com/");
driver.manage().window().maximize();
List<WebElement> prodTitles=driver.findElements(By.xpath("//h2[@class='product-title']"));
List<WebElement> prodPrices=driver.findElements(By.xpath("//div[@class='prices']"));
Map <String,Double>products_map=new HashMap<String,Double>();
for(int i=0;i<prodTitles.size();i++) 
{
String title=prodTitles.get(i).getText();
double price=Double.parseDouble(prodPrices.get(i).getText());
products_map.put(title, price);
}
//Printing titles & prices using for..each loop
System.out.println("**** Printing titles & prices using for..each loop**** ");
for (Map.Entry<String,Double> entry : products_map.entrySet()) {
  System.out.println(entry.getKey()+":"+entry.getValue());
}
// Printing titles & prices using Hashmap .forEach() & Lamda expression
System.out.println("**** Printing titles & prices using lamda expression**** ");
products_map.forEach((t, p) -> System.out.println(t + " : " + p));
//find product whose price is greater than 800 (for..each loop)
System.out.println("**** Product price is > 800 ****");
for (Map.Entry<String,Double> entry : products_map.entrySet()) {
  if(entry.getValue()>800)
  {
  System.out.println(entry.getKey()+":"+entry.getValue());
  }
}
//find product whose price is greater than 800 (Process using filter)
System.out.println("**** Product price is > 800 using filer & lambda ****");
products_map.entrySet().stream().filter( e -> e.getValue() > 800).forEach(v->System.out.println(v));
}

}



Selenium Locators - XPath Axes



XPath axes are those axes that are used to search for the multiple nodes in the XML document from the current node context.
These methods are mainly used when the web element is not identified with the help of ID, name, class name, link text, CSS selector and XPath, etc. locators.

  • Self
  • Parent
  • Child
  • Ancestor
  • Descendant
  • Following
  • Following-sibling
  • Preceding
  • preceding-sibling





Example:

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LocatorsDemo5_XPAthAxes {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","C://Drivers//chromedriver_win32//chromedriver.exe");
WebDriver driver=new ChromeDriver();

driver.get("https://money.rediff.com/gainers/bse/daily/groupa");
driver.manage().window().maximize();

//Self  - Selects the current node
String text=driver.findElement(By.xpath("//a[contains(text(),'India Tourism De')]/self::a")).getText();
System.out.println(text); //India Tourism De


//Parent - Selects the parent of the current node (always One)
text=driver.findElement(By.xpath("//a[contains(text(),'India Tourism De')]/parent::td")).getText();
System.out.println(text);  //India Tourism De

//Child - Selects all children of the current node (One or many)
List childs=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/child::td"));
System.out.println("Number of child elements:"+childs.size());//5

//Ancestor - Selects all ancestors (parent, grandparent, etc.) 
text=driver.findElement(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr")).getText();
System.out.println(text);

//Descendant - Selects all descendants (children, grandchildren, etc.) of the current node
List descendants=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/descendant::*"));
System.out.println("Number of descendant nodes:"+descendants.size());

//Following -Selects everything in the document after the closing tag of the current node
Listfollowingnodes=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/following::tr"));
System.out.println("Number of following nodes:"+followingnodes.size());

//Following-sibling : Selects all siblings after the current node
List followingsiblings=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/following-sibling::tr"));
System.out.println("Number of Following Siblings:"+followingsiblings.size());

//Preceding - Selects all nodes that appear before the current node in the document
List precedings=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/preceding::tr"));
System.out.println("Number of preceding nodes:"+precedings.size());

//preceding-sibling - Selects all siblings before the current node
List precedingsiblings=driver.findElements(By.xpath("//a[contains(text(),'India Tourism De')]/ancestor::tr/preceding-sibling::tr"));
System.out.println("Number of preceding sibling nodes:"+precedingsiblings.size());

driver.close();
}

}

Hands on:
1) Find the sign-up button from the registration form present in the Facebook application. (child)
//div[@id='reg_form_box']/child::div[10]/button

2) Locate Firstname field from SignUp button in facebook (Parent)
//button[@id='u_0_13']//parent::*/parent::*/child::div[1]/div[1]/div[2]
//button[@id='u_0_13']//ancestor::div[2]/child::div[1]/div[1]/div[2]


3) Identify the Password from Mobile number filed in facebook.(Following)
//input[@id='u_0_r']/following::input[2]


4) Locate Mobile number from newpassword field in facebook (preceding)
//input[@id='password_step_input']/preceding::input[2]


5) Locate surname from female radio button in facebook(Ancestor)
//input[@id='u_0_6']/ancestor::div[2]/div[1]/div[1]/div[2]
//input[@id='u_0_6']/ancestor::div[2]//input[@id='u_0_o']

6) Identify the search text box from the Google search button present in the Google search home page. (Parent)
//div[@class='FPdoLc tfB0Bf']//input[@name='btnK']/parent::*/parent::*/parent::*/div[1]


7) Identify the Today’s Deals link from the amazon search text box present in the amazon home page.(Following)
//input[@id='twotabsearchtextbox']/following::a[contains(text(),'Best Sellers')]

8) Identify the Hello, Signin from the amazon search text box present in the amazon home page. (Following)
//input[@id='twotabsearchtextbox']/following::span[contains(text(),'Hello, Sign in')]

9) Identify Mobiles link which is part of Menu bar - Amazon  (Descendant)
//div[@id='nav-xshop']/descendant::a[1]
//div[@id='nav-xshop']/descendant::a[contains(text(),'Mobiles')]

Selenium Locators - XPath


XPath is defined as XML path.
It is a syntax or language for finding any element on the web page using XML path expression. 
XPath is used to find the location of any element on a webpage using HTML DOM structure.
XPath can be used to navigate through elements and attributes in DOM. 

In this article we will disccuss
1) What is XPath?
2) What is DOM?
3) Types of XPath ( Absolute & Relative)
4) Diff between Absolute & Relative xpaths 
5) How to capture XPaths - Extensions for chrome
6) Which XPath is preferred? Why?
7) XPath options
  •    or
  •    and
  •    contains()
  •    starts-with()
  •    text()
  •    chained xpath



Example:
-----------------

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

public class LocatorsDemo4_XPaths {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","C://Drivers//chromedriver_win32//chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("http://automationpractice.com/index.php");
driver.manage().window().maximize();

//Absolute xpath
//driver.findElement(By.xpath("/html[1]/body[1]/div[1]/div[1]/header[1]/div[3]/div[1]/div[1]/div[2]/form[1]/input[4]")).sendKeys("T-shirts");
//driver.findElement(By.xpath("/html[1]/body[1]/div[1]/div[1]/header[1]/div[3]/div[1]/div[1]/div[2]/form[1]/button[1]")).click();

//Relative xpath
//driver.findElement(By.xpath("//input[@id='search_query_top']")).sendKeys("T-shirts");
//driver.findElement(By.xpath("//button[@name='submit_search']")).click();


//xpath with   'or'

//driver.findElement(By.xpath("//input[@id='search_query_top' or @name='search_queryX']")).sendKeys("T-shirts");
//driver.findElement(By.xpath("//button[@name='submit_searchX' or @class='btn btn-default button-search']")).click();

//xpath with 'and'
//driver.findElement(By.xpath("//input[@id='search_query_top' and @name='search_query']")).sendKeys("T-shirts");
//driver.findElement(By.xpath("//button[@name='submit_search' and @class='btn btn-default button-search']")).click();

//xpath with contains()
//driver.findElement(By.xpath("//input[contains(@id,'query_top')]")).sendKeys("T-shirts"); // id=search_query_top
//driver.findElement(By.xpath("//button[contains(@name,'search')]")).click(); // name=submit_search

//xpath with start-with()
//driver.findElement(By.xpath("//input[starts-with(@id,'search_query')]")).sendKeys("T-shirts"); // id=search_query_top
//driver.findElement(By.xpath("//button[starts-with(@name,'submit_')]")).click(); // name=submit_search

//xpath with text()
//driver.findElement(By.xpath("//a[text()='Women']")).click();   // WOMEN Tab

//chained xpath

driver.findElement(By.xpath("//form[@id='searchbox']//input[@id='search_query_top']")).sendKeys("T-shirts");
driver.findElement(By.xpath("//form[@id='searchbox']//button[@name='submit_search']")).click();


}

}

Selenium Locators - Id, Name, LinksText, partial LinkText & CSS Selector



Locators in Selenium are one of the most powerful commands. Its ideally the building block of the Selenium automation scripts. It helps locate the GUI elements through which multiple user actions can be performed. These are one of the important parameters for scripting, and if they end up to be incorrect or brittle, they may lead to script failure. A good scripting base foundation requires elements to be located appropriately. For this, we have multiple locators in Selenium WebDriver. Below is the list of these locators of Selenium WebDriver :
  • Id
  • Name
  • Link Text
  • Partial LinkText
  • ClassName
  • Tag Name
  • CSS Selector
  • XPath



Example 1:
---------------------------------------------
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LocatorsDemo1 {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","C:\\Drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://automationpractice.com/index.php");

driver.manage().window().maximize(); // maximize web page


// id & name locators
WebElement searchbox=driver.findElement(By.id("search_query_top"));
searchbox.sendKeys("T-shirts");

driver.findElement(By.name("submit_search")).click();

//linkText & partial linkText
//driver.findElement(By.linkText("Printed Chiffon Dress")).click();
driver.findElement(By.partialLinkText("Chiffon Dress")).click();

}

}

Example 2:
---------------------------------------------
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LocatorsDemo2 {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","C:\\Drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://automationpractice.com/index.php");

driver.manage().window().maximize(); // maximize web page

//className
int sliders=driver.findElements(By.className("homeslider-container")).size();
System.out.println(sliders);

//TagName
int links=driver.findElements(By.tagName("a")).size();
System.out.println(links);
}

}

Example3
-------------------------------------
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LocatosDemo3 {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","C:\\Drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();

driver.get("https://www.facebook.com/");
driver.manage().window().maximize(); // maximize web page

//Tag & ID
//driver.findElement(By.cssSelector("input#email")).sendKeys("David");
//driver.findElement(By.cssSelector("#email")).sendKeys("David");

// Tag & Class
//driver.findElement(By.cssSelector("input.inputtext")).sendKeys("John");
//driver.findElement(By.cssSelector(".inputtext")).sendKeys("John");

//Tag & attribute
//driver.findElement(By.cssSelector("[name=email]")).sendKeys("Smith");
//driver.findElement(By.cssSelector("input[name=email]")).sendKeys("Smith");

//Tag , class & attribute
driver.findElement(By.cssSelector("input.inputtext[data-testid=royal_email]")).sendKeys("Smith");
driver.findElement(By.cssSelector("input.inputtext[data-testid=royal_pass]")).sendKeys("abc");

}

}

Followers