Home » selenium-tutorial » Object identification on webdriver defined methods

Newly Updated Posts

Object identification on webdriver defined methods

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 .

  1. ) 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:

driver.findElement(By.id(“Email”));

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:

driver.findElement(By.name(“Email”));

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:

driver.findElement(By.className(“inputtext login_form_input_box”));

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:

driver.findElement(By.tagName(“input”));

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 :

driver.findElement(By.linkText(“Forgotten account?”));

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
driver.findElement(By.partialLinkText(“Forgotten”));