Let’s understand driver.findelement in this way-Every web-driver interaction with web has 3 different components-

1- Driver class object- It can be selenium supported browser/driver

2- Locator-Name, ID, Class, Xpath, and CSSs-Selector

3- Test data- Test data which is needed for flow execution

Splitting driver.findelement syntax

In any framework, this above line of code is used to bring in different layers that mean-

1- Initiation of driver object in a different class

2- Locator described in a different class if it is a page factory then in a class, or in a property file

3- Test data is usually stored in external file e.g. excel file, database, etc.

Some of the widely used driver class methods in selenium webdriver are-

1- driver.findelement()- It returns single element, sample syntax-


2-driver.findelements()- It returns list of elements, which means multiple elements have same property.

List<WebElement> ele= driver.findElements(By.cssSelector(“[value=’Test’]”)).click();;

3- driver .close()- is a webdriver command which closes the browser window which has focus. 


4- driver.get()- This webdriver command open web url.


5- driver.getCurrenURL()- This returns current url which is focussed and under execution.

String str; str= driver.getCurrentURL(“www.automatorsworld.com”)

6- driver.Title()- This webdriver command returnds title of web browser. therefore it should be stored in a string data variable.

String str; str = driver.Title();

7- driver.PageSource()- This is a very interesting command, it returns pagesource of opened webbrowser. it returns a string, therefore, this needs to be passed in a string variable.

String str; str = driver.PageSource();

8- driver.getWindow()- this command get the window handle of the current window.

String  handle= driver.getWindowHandle();

9-driver.navigate- This command can be used for opening url, like- driver.navigate().to("http://automatorsworld.com");

This command can be used to move forward and backward too-


10- driver.switchto()- This command this can be used for – switching to Frame, defaultcontent, alert, window and activeelement, like below-

driver.switchto() command

11-driver.manage()- Please find below the command and some useful methods.

driver.manage() command and some useful methods


Selenium has many classes and methods, however, to start understanding them it is important to understand driver.findement first and driver class other methods.

Above mentioned methods are useful which will help in day-to-day test automation needs.

Happy Automating!!!

Follow us at facebook page- https://www.facebook.com/automatorsworld