In this session you will learn what is WebElement and how to define WebElement and different methods available in WebElement Interface
To practice all programs with examples , please download the project from the git repository below
===========================
github.com/knowledgeshare-technologies/SeleniumBas…
WebElement refers to a HTML Element
Everything on a webpage is a WebElement ( Example : radio buttons, checkboxes, dropdowns )
Used to perform actions on a web page ( your testing basically )
All Super interfaces: SearchContext, TakesScreenshot
==================================================
Key Methods that are used frequently
==================================================
1. clear()
2. click()
3. sendKeys(“value”)
4. isDisplayed() 5. isEnabled()
6. isSelected()
7. getSize()
8. getTagName()
9. getText()
Syntax/Example:
WebElement name=driver.findElement(By.id(“value”));
Resource : www.selenium.dev/selenium/docs/api/java/org/openqa…
Example Program for WebElement declaration
====================================
package com.seleniumbasics;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class webElement_example
{
public static void main(String args[])
{
System.setProperty("webdriver.chrome.driver","E:\\Selenium + Java - Youtube\\Selenium\\Libraries\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("demowebshop.tricentis.com/register");
WebElement first_name=driver.findElement(By.id("FirstName"));
WebElement last_name=driver.findElement(By.id("LastName"));
WebElement email_id=driver.findElement(By.name("Email"));
WebElement password=driver.findElement(By.id("Password"));
WebElement confirm_password=driver.findElement(By.id("ConfirmPassword"));
Boolean check_first_name_element_presence =first_name.isDisplayed();
System.out.println("First name present ? :" + check_first_name_element_presence );
String getattribute_last_name=last_name.getAttribute("data-val-required");
System.out.println("get attribute example : " + getattribute_last_name);
if(getattribute_last_name.equalsIgnoreCase("Last name is required."))
{
System.out.println("expected text is present ");
}
first_name.sendKeys("knowledge");
last_name.sendKeys("share");
email_id.sendKeys("testknowledgeshare@gmail.com");
password.sendKeys("123456");
confirm_password.sendKeys("123456");
}
}
コメント