wp.jochen.hayek.name/blog-en

Selenium+XPather: e.g. verifyTextPresent vs. verifyElementPresent

Selenium usually records string clicks and tests instead of true native language independent XPath expressions. But you can always find the right XPath expression yourself (resp. with the help of XPather, a Firefox extension), and make use of it in your selenium code.

Caveat: the XPath expression, that XPather tells you, needs yet another ‘/’ in the beginning to be useful in your Selenium code.

Yes, these XPath expressions are lengthy, and you may think they are overspecifying your location in question, but then: when will that lengthy XPath expression ever fail? If your HTML programmer changes his code. And that’s exactly, what you should insist of being informed of in the first place. Track your HTML programmer! If you don’t, he will screw you w/o any mercy. You don’t want to screw him, but you need to know the consequences of what he is doing. Actually not in every detail, but more details are better than no details at all.

We replaced verifyTextPresent with verifyElementPresent, and it worked “out of the box”. We gained native language independence immediately.

Exit mobile version