My Thoughts: Selenium WebDriver : findElement() Vs findElements() functions

Saturday, May 5

Selenium WebDriver : findElement() Vs findElements() functions



It is very important to know the difference between findElement() and findElements() functions and here you go for it :

findElement() :

  1. Find the first element within the current page using the given "locating mechanism".
  2. Returns a single WebElement.
  3. Syntax: WebElement findElement(By by)

Ex:
driver.get("https://signup.live.com");
WebElement firstName=driver.findElement(By.id("iFirstName"));
firstName.sendKeys("Automated First Name");



findElements() :

  1. Find all elements within the current page using the given "locating mechanism".
  2. Returns List of WebElements.
  3. Syntax:  java.util.List<WebElement> findElements(By by)

Ex:
driver.get("https://signup.live.com");
List  textboxes1=driver.findElements(By.xpath("//input[@type='text']"));
System.out.println("total textboxes "+textboxes1.size());

4 comments:

  1. Your information about selenium is really interesting. Also I
    want to know the latest new techniques which are implemented in Selenium.
    Please update it in your website.

    Selenium
    training Chennai

    ReplyDelete