0% found this document useful (0 votes)
5 views6 pages

Day - 5 - WebElement Methods

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Day - 5 - WebElement Methods

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

WebElement Methods

WebElement is an interface where we can perfrom on checkbox, radio


button,dropdown,hyperlink,button etc.

Methods of webElement

A).sendKeys():

SendKeys() method it is used to send value in perticular textbox.

Syntax:

driver.findElement.sendKeys(“”);

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for firstname text box

driver.findElement(By.name("FirstName")).sendKeys("pooja");

B).click():

click() method it is used to click on button or hyperlink.

Syntax:

driver.findElement.click();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for radio button.

driver.findElement(By.id("gender-female")).click();
C).getText():

getText() method it is used to find text value of element return type of this
method is string.

Syntax:

String s1 = driver.findElement.getText();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for register button.

String txt = driver.findElement(By.xpath("//*[@id='register-


button']")).getText()

D).getAttribute():

getAttribute() this method will get the value from textbox, return type of this
method is String.

Syntax:

String s1 = driver.findElement.getAttribute();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for lastname textbox.

String at =
driver.findElement(By.xpath("//*[@id=\"LastName\"]")).getAttribute("id");
E).clear():

clear() method it is used to clear the text box value.

Syntax:

driver.findElement.clear();

WebSite:- index.html

For Example:- for username textbox.

driver.findElement(By.xpath("//input[@id='uid']")).clear();

F).submit():

submit() method it is just similar like click method.It is used to submit page
value.

Syntax:

driver.findElement.submit();

WebSite:- index.html

For Example:- for login button.

driver.findElement(By.xpath("//button[@id='login']")).submit();

G).isDisplay():

isDisplay() method will check whether the element display or not, return type is
boolean.

Syntax:

boolean br=driver.findElement.isDisplay();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for register button.

Boolean reg = driver.findElement(By.xpath("//*[@id=\"register-


button\"]")).isDisplayed();
H)isSelected():

isSelected() method it is used to check radioButton, checkbox are selected or


not, return type of this method is boolean.

Syntax:

boolean br= driver.findElement.isSelected();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for gender radio button.

boolean br =driver.findElement(By.id("gender-female")).isSelected();

I).isEnabled():

isEnabled() method it is used for button to check whether it is enabled or


disabled, return type of this method is boolean.

Syntax:

Boolean br= driver.findElement.isEnabled();

WebSite:- https://demowebshop.tricentis.com/register

For Example:- for gender radio button.

Boolean check =
driver.findElement(By.xpath("//button[@id='login']")).isEnabled();

You might also like