'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')]");
Solution 1:[1]
td
with certain contents
From your trials, it seems you're fine with keying off of $2.00
literally, so you could use this XPath 2.0 expression to get the td
that ends with $2.00
:
//td[ends-with(normalize-space(), '$2.00')]
Note that browsers don't generally support XPath 2.0, so use this XPath 1.0 expression if running within a browser and you're ok with $2.00
appearing anywhere within the td
:
//td[contains(.,'$2.00')]
Text following a br
If you don't want to literally specify the $2.00
, you'll have to state some other invariant constraint. For example, this XPath will return the string that follows the br
contained within a td
that starts with $3.00
:
normalize-space(//td[starts-with(normalize-space(),'$3.00')]/br/following::text())
See also
Solution 2:[2]
If you need, just add table id or any other specific locator.
xpath=//table//tr/td[2]/text()[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Tomas Chudjak |