In this tutorial, I will list out Selenium WebElement methods. WebElement in a web page is nothing but a text box, button, links, checkbox, radio button, table, window, frames etc.
Selenium WebElement Methods
1. clear() - This method is used to clear the value of text box.
Example: driver.findElement(By.name(“username”)).clear();
2. click() - This method is used to click on the selected WebElement.
Example: driver.findElement(By.name(“submit”)).click();
3. getAttribute(java.lang.String name) - This method is used to get the value from the fields like Text box.
Example: driver.findElement(By.className(“Blogercup”)).getAttribute(“username”);
4. getSize() - This method is used to get the size of the WebElement.
5. getTagName() - This method is used to get the tag name of the selected WebElement.
6. getText() - This method is used to get text from the selected WebElement of the web page.
Example:
List<WebElement> element = driver.findElements(By.name(“q”));
for(int i=0;i<element.size();i++){
System.out.println(element.get(i).getText());
}
7. sendKeys(java.lang.CharSequence… keysToSend) - This method is used to type text in the selected WebElement
Example:
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“Blogercup”);
8. submit() - This method is used to submit a form.
Example:
WebElement element = driver.findElement(By.name(“q”));
element.submit();