Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

html - XPath for text after <br/>

Looking to get the XPath of $2.00 with this block:

<td class="undefined" colspan="6">
   <table class="history-bill-payments" cellspacing="0" cellpadding="0" border="0" align="center" width="99%">
<thead>
<tbody>
   <tr>
      <td valign="top">04/19/2016</td>
      <td valign="top" style="text-align:right; height:">
         $3.00
         <br/>
         $2.00
      </td>

I have tried these but to no avail

$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/following-sibling::br)]"); 
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/preceding-sibling::br/text(),'$2.00')]"); 
$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/following-sibling::br/text(),'$2.00')]");

Using firepath in Firefox I get this XPath

html/body/div[4]/div[2]/div/div/div/div/table/tbody/tr[2]/td/table/tbody/tr/td[2]

I was able to get the xpath of $3.00

$I->CanSeeElement("//table[contains(tbody/tr[2]/td/table/tbody/tr/td[2]/text(),'$3.00')]");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In XPath 1.0, given a node-set, contains() would only evaluates the first node in the set. That's why your initial XPath successfully find text node that contains '$3.00', but not the one that contains '$2.00'.

XPath expression that is close to the way your xpath of $3.00 works would be as follow :

//table[tbody/tr[2]/td/table/tbody/tr/td[2]/text()[contains(.,'$2.00')]]

The XPath above works by applying contains() on individual text node instead of passing multiple text nodes at once.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...