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:
No comments:
Post a Comment