Hi Padraig,
Sorry for so much delay...
Hi,
I extended Watir Ver. 1.4.1 with the Xpath extension. However I'm having problems with the Xpath extension. It has problems identifying nodes using the text they contain. For example a node with:
<DIV>some text</DIV>
Xpath will have trouble finding the DIV tag using the text it contains. If I put the following code in (:xpath, "//div['some totally different text']")It would find the above node. See the example below:
<div id="div2">
<DIV id=spanner>bbb</DIV>
<table id="div2-1">
<input id="div2-2" type=submit value="Hope this works" name=btnWork/>
</table>
<table id="tab2-2"><tr><td id="table col">yyy</td></tr></table>
</div>If I use this Xpath (:xpath, "//[EMAIL PROTECTED]'div2']/*/.='blah blah'") it'll fine the node <DIV id=spanner>bbb</DIV>. It finds the first element without looking at the end of the XPath statement.
You cant search for an node based on the text it contains! Will Watir Ver. 1.5 contain the same Xpath version that's now available in Head in CVS or is to plan to modify. Should I wait to see if the new version will fix this problem or go the awkward route of trying to change the way the tag elements are generated? Has anybody else come across the same problems?
The xpath that you are using is wrong. So it will depend upon REXML implementation what results it will give. For the above case the xpath query should be:
//[EMAIL PROTECTED]'div2']/*/[.,'blah blah']
when ever you want to compare some attribute in xpath query, you need to give the condition inside square bracket. The above xpath query will give you the no element because there is no child element of 'div2' whose text is 'blah blah'.
You can use this tool for testing the xpath:
http://www.topxml.com/downloads/default.asp?id=visualiser
But first you have to convert you HTML file to XHTML file using Tidy..
Also you can use the following code to test you xpath:
include REXML
doc = REXML::Document.new( %q{<div id="div2">
<div id="spanner">
bbb
</div><input id="div2-2" type="submit" value="Hope this works" name="btnWork" />
<table id="div2-1"></table>
<table id="tab2-2">
<tbody>
<tr>
<td id="table col">yyy</td>
</tr>
</tbody>
</table>
</div>})
doc.root.elements.each("//[EMAIL PROTECTED]'div2']/*/[.='blah blah']") { |element| puts element.expanded_name }
If you xpath query is correct then this code will print the tag of the element that you are selecting.
Regards,
Angrez
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
