As all knows xpath is differentiated in 2 ways while getting used in selenium, one is absolute and other is relative. Nowadays chrome browser helps user with the option available in the browser to copy the xpath which can be used directly in the script.
But many times the xpath provided by the browser is not correct or the property used in that is dynamic. So we have to write it down. I am providing the below examples which will help you to write down the xpath with correct syntax's and different identifiers also.
Using Text of the Object
If you don't know the html tag of the object.
"//*[text()='text of object']"
If you know the html tag of the object.
"//a[text()='text of object']"
If don't know the whole text but only few character. But make sure it should be unique.
"//*[contains(text(),' character of the text object')]"
"//*[contains(@id,' character of the id')]"
But many times the xpath provided by the browser is not correct or the property used in that is dynamic. So we have to write it down. I am providing the below examples which will help you to write down the xpath with correct syntax's and different identifiers also.
Using Text of the Object
If you don't know the html tag of the object.
"//*[text()='text of object']"
If you know the html tag of the object.
"//a[text()='text of object']"
If don't know the whole text but only few character. But make sure it should be unique.
"//*[contains(text(),' character of the text object')]"
"//*[contains(@id,' character of the id')]"
No comments:
Post a Comment