Showing posts with label Introduction of Selenium Locators. Show all posts
Showing posts with label Introduction of Selenium Locators. Show all posts

Wednesday, April 15, 2020

Selenium Locators - Common Locators


1> By ID: This is most common method to locate the element as it always give one to one mapping.


Syntax: By.id("Value of ID");
Example: driver.findElement(By.id("fname"));

Practical Example: Right Click on Element and Select Inspect Element



Code Example in eClipse: 




2> By Name: This is another most favourite method after ID as it works similar way and give more chance for one to one mapping.



Syntax: By.name("Value of Name");
Example: driver.findElement(By.name("lastname"));

Practical Example: Right Click on Element and Select Inspect Element





Code Example in eClipse: 



3> By ClassName: This will locate the web element based on value of class name.


Syntax: By.className("Value of ClassName");
Example: driver.findElement(By.className("gh089b"));

Practical Example: Right Click on Element and Select Inspect Element



Code Example in eClipse: 




4> By LinkText : This will locate the web element based on link text value available in anchor tag.



Syntax: By.linkText("LinkText Value");
Example: driver.findElement(By.linkText("Facebook_Link"));

Practical Example: Right Click on Element and Select Inspect Element





Code Example in eClipse: 




5> By LinkText : This will locate the web element based on link text value available in anchor tag.


Syntax: By.partialLinkText("Partial Text Value");

Example: driver.findElement(By.partialLinkText("an Email"));

Practical Example: Right Click on Element and Select Inspect Element




Code Example in eClipse: 






Tuesday, April 14, 2020

Introduction of Selenium Locators


Locator in simple term location of web element, which help 

Selenium to perform the operation on them.

Web elements should be text box, button, checkbox, radio button, links, drop down etc.

Selenium interact with web element using the locators.


Below are the common types of locators available in Selenium:

  • By ID
  • By Name
  • By Class Name
  • By Link Text
  • By Partial Link Text

  •     Absolute XPath
  •     AND Condition
  •     OR Condition
  •     Multiple Attributes

  •     Contains() Method
  •     Starts-with Method
  •     Text() Method
  •     Last() Method
  •     Position() Method

  •     Tag and ID
  •     Tag and Class
  •     Tag and Attribute
  •     Tag, Class & Attribute

  •      Starts-with (^)
  •      End-with ($)
  •      Contains (*)