SDET- QA Automation Techie

Software Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

Difference between findElement() and findElements()

 Difference between findElement() and findElements()   

In this post, we will learn the difference between findElement() and findElements(). These are the important methods  which are used for finding elements on the WebPage.

Usage of findElement():

This is used to find the WebElement  like Button, checkbox,radio button etc. on the page.The different locator (id,name,xpath etc.) are used within it to find the elements.
Syntax:
driver.findElement(By.xpath(“XPATH expression”));
driver.findElement(By.id(“Id of element”));
driver.findElement(By.name(“name of element”));


As an example, we will try to locate the ‘Google search’button on the Google page. We will use its name attribute as it is unique(shown in the figure below).
isdisplayed in selenium
We use ‘isDisplayed()’ method, which returns true value if it finds the element else false. We are printing true or false result in the console by using ‘System.out.println’.
1
2
3
4
5
6
7
8
9
10
11
public class ExampleFindElement {
private static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
System.out.println(driver.findElement(By.name("btnK")).isDisplayed());
}
}
Output: true

Usage of findElements(): 

The method fincElements() returns a list of WebElements on the page. We can work over that list according to our need.
Suppose, we need to count the no. of links on the Google Page. As we know link is represented by tag ‘a’ in html. So, we will use the method ‘tagName’ to count the total no. of links.
1
2
3
4
5
6
7
8
9
10
11
12
13
public class ExampleFindElements {
private static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
List totalLinks = driver.findElements(By.tagName("a"));
System.out.println("Total links : "+totalLinks.size()); // total links
}
}
Total links : 46
You might be surprised after seeing the output 46, but when we look at google page , it does not seem to have 46 links. You don't need to worry about that , there are some hidden links which are not visible to us but selenium can detect them. That’s why it has returned count as 46.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates