We have already learned about Xpath locator in previous posts.
Following are different example of Xpath locator:
Xpath Locator based on id of element:
For example,
is the xpath based on id for Name textbox in above html code.
Xpath Locator based on name of element:
For example,
is the xpath based on name for Email Address textbox in above html code.
Xpath Locator based on class of element:
For example,
is the xpath based on class for Submit button in above html code.
Xpath Locator based on value of element:
For example,
is the xpath based on value for Submit button in above html code.
Xpath Locator based on containing text by element:
For example,
is the xpath based containing text for Name label in below html code.
Following are different example of Xpath locator:
- <div class="MsoListParagraphCxSpFirst">
- <table id="table1"><o:p></o:p></div>
- <div class="MsoListParagraphCxSpMiddle">
- <form method="POST"
- action="#"><o:p></o:p></div>
- <div class="MsoListParagraphCxSpMiddle">
- <tbody><o:p></o:p></div>
- <div class="MsoListParagraphCxSpMiddle">
- <tr><td>Name: </td><td><input
- type="text" id="name" size="20"></td></tr><o:p></o:p></div>
- <div class="MsoListParagraphCxSpMiddle">
- <tr><td>Email Address: </td><td><input
- type="text" name="email" size="20"></td></tr><o:p></o:p></div>
- <div class="MsoListParagraphCxSpMiddle">
- <tr><td><input
- type="submit" value="Submit"
- class="button"></td></tr><o:p></o:p></div>
- <div class="MsoListParagraphCxSpLast">
- </tbody><o:p></o:p></div>
- </table>
Xpath Locator based on id of element:
For example,
- xpath=//input[@id='name']
Xpath Locator based on name of element:
For example,
- xpath=//input[@name='email']
Xpath Locator based on class of element:
For example,
- xpath=//input[@class='button']
Xpath Locator based on value of element:
For example,
- xpath=//input[@value='Submit ']
Xpath Locator based on containing text by element:
For example,
- xpath=//p[contains(text(),'Name')]
No comments:
Post a Comment