Selenium WebDriver Commands With Example
- What is WebDriver?
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.
--> 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());