Wednesday, December 4, 2013

Selenium WebDriver Commands With Example

Selenium WebDriver Commands With Example

  • What is WebDriver? 
WebDriver is a tool for writing automated tests web applications. It aims to mimic the behavior of a real user, and as such interacts with the HTML of the application.

1. What is WebDriver "By" class?
--> Mechanism used to locate elements within a document. 
Direct Known Subclasses:
By.ByClassName, By.ByCssSelector, By.ById, By.ByLinkText, By.ByName, By.ByPartialLinkText, By.ByTagName, By.ByXPath, ByAll, ByChained, ByIdOrName

2. Difference between findElement() and findElements() functions?
--> findElement() : Returns a single WebElement within the current page

Syntax: WebElement findElement(By by)

driver.get("https:www.gmail.com");
WebElement userName=driver.findElement(By.id("username"));
userName.sendKeys("ravismundhe");

-- findElements() : Returns List of WebElements within the current page.

Syntax: WebElement findElements(By by)

driver.get("https://www.matrix.com");
List <webelement> textboxes1=driver.findElements(By.xpath("//input[@type='text']"));
System.out.println("total textboxes "+textboxes1.size());