It is very important to know the difference between findElement() and findElements() functions and here you go for it :
findElement() :
- Find the first element within the current page using the given "locating mechanism".
- Returns a single WebElement.
- 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() :
- Find all elements within the current page using the given "locating mechanism".
- Returns List of WebElements.
- Syntax: java.util.List<WebElement> findElements(By by)
Ex:
- driver.get("https://signup.live.com");
- List <webelement> textboxes1=driver.findElements(By.xpath("//input[@type='text']"));
- System.out.println("total textboxes "+textboxes1.size());
- </webelement>
No comments:
Post a Comment