[Webtest] Am I using XPATH correctly?
Dierk Koenig
webtest@lists.canoo.com
Thu, 13 Jul 2006 20:05:55 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0020_01C6A6B7.BFEACD20
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Hi,
your html code isn't fully correct. It misses a tbody elements to enclose
the tr tabs.
The browsers don't mind but the html parser that comes with htmlunit puts
those missing elements in the dom.
You may profit from relaxing your your XPATH a bit like
string(//div[@id='etContent']/form//tr[1]/td[2]//b[1])
that also makes it easier to maintain
Xpath engines differ slightly between stylus, XPE, and HtmlUnit but this is
unlikely to be the source of your problem.
cheers
Mittie
-----Original Message-----
From: webtest-admin@lists.canoo.com
[mailto:webtest-admin@lists.canoo.com]On Behalf Of dlundin@aol.com
Sent: Donnerstag, 13. Juli 2006 19:12
To: webtest@lists.canoo.com
Subject: [Webtest] Am I using XPATH correctly?
Hello all,
I have a webpage I am trying to use WebTest/XPATH to extract a value. I've
cut-and-pasted the html in this post. I've confirmed the XPATH is correct
using XPATH Explorer and Stylus tools.
Here are some things I've seen:
- The value I'm trying to grab is within a bold tag
- The value is preceeded and succeeded by embedded tab characters (I can't
change)
Here's the XPATH (I've also removed the string function and given an
absolute path - no change):
string(//div[@id='etContent']/form[1]/table[1]/tr[2]/td[2]/div[1]/table[1]
/tr[1]/td[1]/table[2]/tr[1]/td[1]/table[1]/tr[1]/td[2]/font[1]/b[1])
My WebTest script does not report an error but, instead, appears to show a
blank value (could this be the result of the tab?)
Is this an XPATH 1.0 vs. 2.0 issue? Does WebTest use XPATH 1.0 or 2.0?
I'm stumped - help, please.
Thanks
-----------------
<table border="0" cellpadding="3" cellspacing="1" width=100%
bgcolor="#999999">
<tr>
<td bgcolor="#cccccc" height="30"><b>Last<br>Price</b></td>
<td nowrap bgcolor="#ffffcc"><font size="3"><b>
14.20
</b></font>
</td>
---------------------
----------------------------------------------------------------------------
--
Check out AOL.com today. Breaking news, video search, pictures, email and
IM. All on demand. Always Free.
------=_NextPart_000_0020_01C6A6B7.BFEACD20
Content-Type: text/html;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2900.2912" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>Hi,</FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>your=20
html code isn't fully correct. It misses a tbody elements to enclose the =
tr=20
tabs. </FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>The=20
browsers don't mind but the html parser that comes with htmlunit puts =
those=20
missing elements in the dom.</FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>You=20
may profit from relaxing your your XPATH a bit like</FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006>
<DIV><FONT face=3DArial><FONT color=3D#0000ff><FONT size=3D2><SPAN=20
class=3D549315617-13072006> =20
</SPAN>string(//div[@id=3D'etContent']/form<SPAN=20
class=3D549315617-13072006>/</SPAN>/tr[1]/td[2]//b[1])</FONT></FONT></FON=
T></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>that=20
also makes it easier to maintain</FONT></SPAN></DIV></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>Xpath=20
engines differ slightly between stylus, XPE, and HtmlUnit but this is =
unlikely=20
to be the source of your problem.</FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>cheers</FONT></SPAN></DIV>
<DIV><SPAN class=3D549315617-13072006><FONT face=3DArial color=3D#0000ff =
size=3D2>Mittie</FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
<DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
size=3D2>-----Original Message-----<BR><B>From:</B>=20
webtest-admin@lists.canoo.com =
[mailto:webtest-admin@lists.canoo.com]<B>On=20
Behalf Of </B>dlundin@aol.com<BR><B>Sent:</B> Donnerstag, 13. Juli =
2006=20
19:12<BR><B>To:</B> webtest@lists.canoo.com<BR><B>Subject:</B> =
[Webtest] Am I=20
using XPATH correctly?<BR><BR></FONT></DIV>
<DIV>Hello all,</DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV>I have a webpage I am trying to use WebTest/XPATH to extract a =
value.=20
I've cut-and-pasted the html in this post. I've confirmed the XPATH is =
correct=20
using XPATH Explorer and Stylus tools.</DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV>Here are some things I've seen:</DIV>
<DIV>- The value I'm trying to grab is within a bold tag</DIV>
<DIV>- The value is preceeded and succeeded by embedded tab characters =
(I=20
can't change)</DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV>Here's the XPATH (I've also removed the string function and given =
an=20
absolute path - no change):</DIV>
<DIV><FONT size=3D2>
=
<DIV>string(//div[@id=3D'etContent']/form[1]/table[1]/tr[2]/td[2]/div[1]/=
table[1]/tr[1]/td[1]/table[2]/tr[1]/td[1]/table[1]/tr[1]/td[2]/font[1]/b[=
1])</DIV></FONT></DIV>
<DIV> </DIV>
<DIV>My WebTest script does not report an error but, instead, appears =
to show=20
a blank value (could this be the result of the tab?)</DIV>
<DIV> </DIV>
<DIV>Is this an XPATH 1.0 vs. 2.0 issue? Does WebTest use XPATH =
1.0 or=20
2.0?</DIV>
<DIV> </DIV>
<DIV>I'm stumped - help, please.</DIV>
<DIV> </DIV>
<DIV>Thanks</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>-----------------</DIV>
<DIV><FONT size=3D2>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><table =
border=3D"0"=20
cellpadding=3D"3" cellspacing=3D"1" width=3D100%=20
bgcolor=3D"#999999"><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: 1"> =20
</SPAN><tr><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
2"> =20
</SPAN><td bgcolor=3D"#cccccc"=20
=
height=3D"30"><b>Last<br>Price</b></td><o:p></=
o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
2"> =20
</SPAN><td nowrap bgcolor=3D"#ffffcc"><font=20
size=3D"3"><b><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
3"> &nbs=
p; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
4"> &nbs=
p; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
5"> &nbs=
p;  =
; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
6"> &nbs=
p;  =
; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
6"> &nbs=
p;  =
; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
7"> &nbs=
p;  =
; =
=20
</SPAN>14.20<o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
6"> &nbs=
p;  =
; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
5"> &nbs=
p;  =
; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
4"> &nbs=
p; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
4"> &nbs=
p; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
3"> &nbs=
p; =20
</SPAN><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
2"> =20
</SPAN></b></font><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN=20
style=3D"mso-tab-count: =
2"> =20
</SPAN></td><o:p></o:p></SPAN></DIV>
<DIV class=3DMsoNormal=20
style=3D"MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: 'Courier =
New'"><o:p> </o:p></SPAN></DIV>
<DIV class=3DMsoNormal style=3D"MARGIN: 0in 0in 0pt"><o:p><FONT=20
face=3D"Times New Roman" size=3D3> </FONT></o:p></DIV>
<DIV>---------------------</DIV></FONT></DIV>
<DIV class=3DAOLPromoFooter>
<HR style=3D"MARGIN-TOP: 10px">
<A=20
=
href=3D"http://pr.atwola.com/promoclk/1615326657x4311227241x4298082137/ao=
l?redir=3Dhttp%3A%2F%2Fwww%2Eaol%2Ecom"=20
target=3D_blank><B>Check out AOL.com today</B></A>. Breaking news, =
video search,=20
pictures, email and IM. All on demand. Always=20
Free.<BR></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0020_01C6A6B7.BFEACD20--