Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')]");
like image 946
kapperkp Avatar asked Apr 19 '16 12:04

kapperkp


2 Answers

If you need, just add table id or any other specific locator.

xpath=//table//tr/td[2]/text()[2]
like image 188
Tomas Chudjak Avatar answered Oct 05 '22 14:10

Tomas Chudjak


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.

like image 25
har07 Avatar answered Oct 05 '22 13:10

har07