[Webtest] Am I using XPATH correctly?

webtest@lists.canoo.com webtest@lists.canoo.com
Thu, 13 Jul 2006 14:50:35 -0400


----------MailBlocks_8C874C45C57CCD3_15B4_5BCF_FWM-R15.sysops.aol.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Mittie,
 
I don't have any way of modifying the html code ... is there anything else I can do?
 
Thanks
Doug 
 
-----Original Message-----
From: dierk.koenig@canoo.com
To: webtest@lists.canoo.com
Sent: Thu, 13 Jul 2006 12:05 PM
Subject: RE: [Webtest] Am I using XPATH correctly?


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.
________________________________________________________________________
Check out AOL.com today. Breaking news, video search, pictures, email and IM. All on demand. Always Free.

----------MailBlocks_8C874C45C57CCD3_15B4_5BCF_FWM-R15.sysops.aol.com
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit

<HTML><BODY>
<div>Mittie,</div>


<div>&nbsp;</div>


<div>I don't have any way of modifying the html code ... is there anything else I can do?</div>


<div>&nbsp;</div>


<div>Thanks</div>


<div>Doug&nbsp;</div>
&nbsp;<br>
-----Original Message-----<br>
From: dierk.koenig@canoo.com<br>
To: webtest@lists.canoo.com<br>
Sent: Thu, 13 Jul 2006 12:05 PM<br>
Subject: RE: [Webtest] Am I using XPATH correctly?<br>
<br>

<STYLE>
.AOLPlainTextBody {
    margin: 0px;
    font-family: Tahoma, Verdana, Arial, Sans-Serif;
    font-size: 12px; 
    color: #000; 
    background-color: #fff; 
}

.AOLPlainTextBody pre {
    font-size: 9pt;
}

.AOLInlineAttachment {
    margin: 10px;
}

.AOLAttachmentHeader {
    font: 11px arial;
    border: 1px solid #7DA8D4;
    background: #F9F9F9;
}

.AOLAttachmentHeader .Title {
    font: 11px arial;
    background: #B5DDFA;
    padding: 3px 3px 3px 3px;
}

.AOLAttachmentHeader .FieldLabel {
    font: 11px arial; 
    color: #000000;
    padding: 1px 10px 1px 9px;
    background: #F9F9F9;
}

.AOLAttachmentHeader .FieldValue {
    font: 11px arial; 
    color: #000000;
    background: #F9F9F9;
}

.AOLAttachmentHeader a, .AOLImage a {
    color: #2864B4;
    text-decoration: none;
}

.AOLAttachmentHeader a:hover, .AOLImage a:hover {
    color: #2864B4;
    text-decoration: underline;
}

body {
    background-color: white;
    font-family: "Verdana";
    font-size: 10pt;
    border: 0px;
}

.spell {
    padding-bottom:2px;
    background:yellow url(images/bg_spellingErr.gif) bottom left repeat-x;
    color:#000;
}

.spellHover {
    text-decoration:none;
    color:#b00;
    padding-bottom:2px;
    background:yellow url(images/bg_spellingErr.gif) bottom left repeat-x;
}

p {
    margin: 0px;
    padding: 0px;
}

img.managedImg {
    width: 0px;
    height: 0px;
}

img.placeholder {
    width: 275px;
    height: 206px;
    background: #F4F4F4 url(images/activityIndicator.gif) center center no-repeat;
    border: 1px solid #DADAD6 !important;  
}

</STYLE>


<div id=AOLMsgPart_2_69ba8255-25ec-4dd2-bf45-463f048ba55f>

<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>Hi,</FONT></SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2></FONT></SPAN>&nbsp;</div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>your html code isn't fully correct. It misses a tbody elements to enclose the tr tabs. </FONT></SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>The browsers don't mind but the html parser that comes with htmlunit puts those missing elements in the dom.</FONT></SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>You may profit from relaxing your your XPATH a bit like</FONT></SPAN></div>


<div><SPAN class=549315617-13072006>

<div><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN class=549315617-13072006>&nbsp;&nbsp;&nbsp; </SPAN>string(//div[@id='etContent']/form<SPAN class=549315617-13072006>/</SPAN>/tr[1]/td[2]//b[1])</FONT></FONT></FONT></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>that also makes it easier to maintain</FONT></SPAN></div>
</SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2></FONT></SPAN>&nbsp;</div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>Xpath engines differ slightly between stylus, XPE, and HtmlUnit but this is unlikely to be the source of your problem.</FONT></SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2></FONT></SPAN>&nbsp;</div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>cheers</FONT></SPAN></div>


<div><SPAN class=549315617-13072006><FONT face=Arial color=#0000ff size=2>Mittie</FONT></SPAN></div>

<BLOCKQUOTE dir=ltr style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">

<div class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<br>
<B>From:</B> webtest-admin@lists.canoo.com [mailto:webtest-admin@lists.canoo.com]<B>On Behalf Of </B>dlundin@aol.com<br>
<B>Sent:</B> Donnerstag, 13. Juli 2006 19:12<br>
<B>To:</B> webtest@lists.canoo.com<br>
<B>Subject:</B> [Webtest] Am I using XPATH correctly?<br>
<br>
</FONT></div>


<div>Hello all,</div>


<div><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</div>


<div>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.</div>


<div><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</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 can't change)</div>


<div><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</div>


<div>Here's the XPATH (I've also removed the string function and given an absolute path - no change):</div>


<div><FONT size=2>

<div>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])</div>
</FONT></div>


<div>&nbsp;</div>


<div>My WebTest script does not report an error but, instead, appears to show a blank value (could this be the result of the tab?)</div>


<div>&nbsp;</div>


<div>Is this an XPATH 1.0 vs. 2.0 issue?&nbsp;Does WebTest use XPATH 1.0 or 2.0?</div>


<div>&nbsp;</div>


<div>I'm stumped - help, please.</div>


<div>&nbsp;</div>


<div>Thanks</div>


<div>&nbsp;</div>


<div>&nbsp;</div>


<div>-----------------</div>


<div><FONT size=2>

<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&lt;table border="0" cellpadding="3" cellspacing="1" width=100% bgcolor="#999999"&gt;<?xml:namespace prefix = o ns = "=" /><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;tr&gt;<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;td bgcolor="#cccccc" height="30"&gt;&lt;b&gt;Last&lt;br&gt;Price&lt;/b&gt;&lt;/td&gt;<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;td nowrap bgcolor="#ffffcc"&gt;&lt;font size="3"&gt;&lt;b&gt;<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>14.20<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;/b&gt;&lt;/font&gt;<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;/td&gt;<o:p></o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></div>


<div class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></div>


<div>---------------------</div>
</FONT></div>


<div class=AOLPromoFooter>
<HR style="MARGIN-TOP: 10px">
<A href="http://pr.atwola.com/promoclk/1615326657x4311227241x4298082137/aol?redir=http%3A%2F%2Fwww%2Eaol%2Ecom" target=_blank><B>Check out AOL.com today</B></A>. Breaking news, video search, pictures, email and IM. All on demand. Always Free.<br>
</div>
</BLOCKQUOTE></div>
<!-- end of AOLMsgPart_2_69ba8255-25ec-4dd2-bf45-463f048ba55f --></BODY></HTML>

----------MailBlocks_8C874C45C57CCD3_15B4_5BCF_FWM-R15.sysops.aol.com--