[ptt-users] Xpath issue

Olivier Dony olivier.dony at denali.be
Wed Sep 26 05:05:23 PDT 2007


On Sep 26, 2007, at 10:54 AM, bl8cki wrote:
> Hello all,
>
> I want to ask you about Xpath in TestGen4Web generated scripts.
> Strange thing for me is that A[@ID="..."] is working but //A 
> [@ID="..."] is not working.
>
> And can i use things like: A/SPAN[text()="some text"] ? This is  
> really important for me, because the webapp i'm testing is using  
> only dynamic ids.
> So i can not rely on them.

That's because the current version of TestGen4Web uses pseudo-XPath  
expressions.
It does look like XPath, but it is neither generated by an XPath  
engine, nor evaluated by one.
I don't think it can handle predicates using text() and the like,  
however it uses a fake attribute value "@CDATA" to represent text().
Maybe A/SPAN[@CDATA="some text"] would work for you? (although I  
recall having problems with it when there is whitespace around the text)
You can also use positions in the DOM to work around dynamic  
attribute values, such as:
    */A/SPAN[1]

If you are interested in the technical details, this is all  
implemented by javascript functions in TG4W's findobject.js file,  
which you can read locally at chrome://recorder/content/ 
findobject.js. The recursive functions getXpath(obj, suffix) and  
getObject(obj, parentDocument, xpath) handle the pseudo-XPath.

I don't know if this is explained somewhere (I'd like to see this in  
a FAQ page). Maybe there's also more about this in the TestGen4Web  
forum at spikesource.com.

Now on the bright side, the test engine in TestMaker does not have  
the same limitations. When you use a TestGen4Web scenario within  
TestMaker, a conversion layer translates the pseudo-XPath expressions  
into real XPath on-the-fly, before passing them to the test engine.  
Nothing forbids using real XPath expressions there.
And soon it should become possible to use selenium-ide (openqa.org)  
as a scenario recorder, in conjunction with TestMaker, as an  
alternative to TG4W.
As selenium-ide can handle real XPath expressions, writing tests  
should become much more flexible.

Cheers,


--
Olivier Dony,

Denali s.a., "Bridging the gap between Business and IT"
Rue de Clairvaux 8, B-1348 Louvain-la-Neuve, Belgium
Office: +32 10 43 99 51  Fax: +32 10 43 99 52
www.denali.be

Legal Notice: This message may contain confidential and/or privileged  
information. If you are not the addressee or authorized to receive  
this for the addressee, you must not use, copy, disclose or take any  
action based on this message or any information herein. If you have  
received this message by mistake, please advise the sender  
immediately by return e-mail and delete this message from your  
system. Thank you for your cooperation.




More information about the Users mailing list