Selenium Webdriver interacts with webpage through object identification. Identification of any web element is performed by reading its source code and finding the unique value of the defined webelement.
Identification of object in selenium performed using findElement() and findElements().
There are few object identification techniques in webdriver .
- ) Locating Element By Id-> To locate element on the basis of id, perform below scenarion.
- Firstly open an application (for ex: www.facebook.com)
- Move to login page and click to F12 button on you keyboard . The source code will open
- Now click to arrow on the source code window on top (highlighted in yellow).
- Now after click take the mouse cursor to the text box on “Email or phone” and click the source code for the text box will be displayed down. Now view the tag for id and copy its value “Email”.
- In the automation test case write below code to locate element on basis of id:
2) Locating Element By Name: Similar way as we identified or located the element by id, we perform the same steps an able to locate the element on basis of Name for the unique identification.
In the automation test case object location by name is performed using below code:
3) Locating Element By Class Name: Object identification using Class Name is performed by using blow line of code and using the same technique as above.
In the automation test case object location by Class Name is performed using below code:
4) Locating Element By Tag Name: Object identification using Tag Name is performed by using blow line of code and using the same technique as displayed in case of ID.
In the automation test case object location by Tag Name is performed using below code:
5) Locating Element By Link Text: Object identification for the link text is identified for the link visible in Web page generally it is present in <a href tag and ends with </a>.
In the automation test case object location by Link Text is performed using below code as per the below example :
5) Locating Element by Partial Link Text: If we want of locate any element in a web page by providing the partial link value. So this can be done by Partial Link Text command as below.
// Locating Element on basis of partial link text