There is no one way to write an xPath statement, but there is good and bad ways.
Things to think about
• Avoid including text in xPath statement as then test won't work in a different language
• Beware of other objects in the page which may use the same attributes
• Always narrow down to a particular code block which can be uniquely identified
Example:
Option1:
//div[@id='list']/table/tbody/tr/td/div[2]/a
Option2:
//div[@id='list']/table/tbody/tr/td/div/a[contains(text(),'Welcome users who')]
Option3:
//div[@id='list']//a[contains(text(),'Welcome users who')]
Option4:
//div[@id='list']//a[contains(@href,'notify.do?user=welcome')]
Option 4 is the best way to identify the link!
Things to think about
• Avoid including text in xPath statement as then test won't work in a different language
• Beware of other objects in the page which may use the same attributes
• Always narrow down to a particular code block which can be uniquely identified
Example:
Option1:
//div[@id='list']/table/tbody/tr/td/div[2]/a
Option2:
//div[@id='list']/table/tbody/tr/td/div/a[contains(text(),'Welcome users who')]
Option3:
//div[@id='list']//a[contains(text(),'Welcome users who')]
Option4:
//div[@id='list']//a[contains(@href,'notify.do?user=welcome')]
Option 4 is the best way to identify the link!
No comments:
Post a Comment