How to write the xpath for dependent nodes?

Hi All,
Can anyone provide me the solution for below query.

<div class="center">

<div class="scrollable">

<span class="buyprice">

<span class="result-name">Product name</span>

<span class="result-transaction-type">BUY</span>

</span>

</div>

<span class="orders-amount">

<span class="total-amount-type">Total CASH  to Customer</span>

<span class="result-total-amount">300.00</span>

</span>

</div>
<div class="center">

<div class="scrollable">

<span class="sellprice">

<span class="result-name">Product name</span>

<span class="result-transaction-type">SELL</span>

</span>

</div>

<span class="orders-amount">

<span class="total-amount-type">Total CASH from Customer</span>

<span class="result-total-amount">50.00</span>

</span>

</div>
<div class="center">

<div class="scrollable">

<span class="refundprice">

<span class="result-name">Product name</span>

<span class="result-transaction-type">REFUND</span>

</span>

</div>

<span class="orders-amount">

<span class="total-amount-type">Total CASH/Card to Customer</span>

<span class="result-total-amount">100.30</span>

</span>

</div>
 

Here I want to get the ‘result-total-amount’ based on buyprice/sellprice/refundprice.

like <span class=’refundprice’>.

The result may differ everytime.Sometimes there buyprice records may be displayed more or sometimes sellprice records may be more.At last I want to get the total of Buy and refund and Sell..

So how can i write the xpath for this.

Please help me ASAP.

Add Comment
  • 1 Answer(s)

    Try this.

    |@FindBy(xpath = “.//div[span[span[span[contains(text(),’REFUND’)]]]]/following-sibling::span[1]//[@class=’result-total-amount’]”)

    WebElement refundResult;

    refundResult.getText();

    Reviewer Answered on June 25, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.