WHAT IS XPATH LOCATOR IN SELENIUM?

Following are different example of Xpath locator:




<table id="table1">
<form method="POST"
action="#">
<tbody>
<tr><td>Name: </td><td><input
type="text" id="name" size="20"></td></tr>
<tr><td>Email Address: </td><td><input
type="text" name="email" size="20"></td></tr>
<tr><td><input
type="submit" value="Submit"
class="button"></td></tr>
</tbody>
</table>



Xpath Locator based on id of element:
For example,
xpath=//input[@id='name']
is the xpath based on id for Name textbox in above html code.

Xpath Locator based on name of element: 
For example,
xpath=//input[@name='email']
is the xpath based on name for Email Address textbox in above html code.



Xpath Locator based on class of element: 
For example,
xpath=//input[@class='button']
is the xpath based on class for Submit button in above html code.

Xpath Locator based on value of element: 
For example,
xpath=//input[@value='Submit ']
is the xpath based on value for Submit button in above html code.

Xpath Locator based on containing text by element: 
For example,
xpath=//p[contains(text(),'Name')]
is the xpath based containing text for Name label in below html code.


Post a Comment

0 Comments