So far, we have learned how to launch a web browser, entering values in a text box and clicking button.
In this post, we will learn about findelement method.

Test automation is all about get and set, which means get from web and set into web.

Talking more specifically-

What I meant from get is, reading a webobject property e.g. Reading a label value of web, which is using findelement.

What I meant by set is, setting values in web for e.g. Inserting values in a text box, clicking a button, selecting a radio button, again using findelement method.

So findelement is a method which helps in interaction with a web page.

How it’s represented and does it work-

It’s written as –

Driver. Findelement(By. Id("")). Click().

WebDriver object allows access to findelement and with help of web object property is finds the designated object and perform operation.

There is another method which is known as findelements.

What is findelements()?

If a web object returns multiple values then findelements are used.

There should be some list, set or array variable be mentioned on the left side which can contain/store returned values-

It’s represented as-

List <WebElement> list= driver. Findelements(By. Id() ) ;

If you can compare with findelement method there is no click or get text method called. Same is done while in list object by iterating it Inside a loop.



el. Gettext() ;


Common Questions-

1- What is the difference bewteen findelement and findelements

Answer- Findelement return single element where as findelements return multiple elements

2- What is the data type which find element or findelements return.

Answer- String

3- What are possible cases when findelement return nothing or null or exception

Answer- Case 1- When page is not loaded when findelement is being called
Case 2- When element property is changed
Case 3- When there is a frame is introduced


Findelement, findelements method is accessed uding webdriver object whic is an interface. They helps in locating a web element or group of elements which have same properties.

It also helps in interaction which ultimately create a bridge between web page and you test/test data and execute test automation script.

Stay connected, In our next post we will learn how to find Xpath and CssSelector