How to loop through all the child div inside parent div and find the li tag value of child div?

2,630 views
Skip to first unread message

Sumit Mishra

unread,
Mar 26, 2014, 2:08:22 AM3/26/14
to seleniu...@googlegroups.com
Hello,

My parent div is "inOfferBox" and child div like"buyback_1" and "buyback_2".. My child div is generating run time and try to find out the "li" tag value of child div. I have also attached the screen shot of my application

Here my Html tag.

<div id="inOfferBox" class="reg12">
<div id="inOfferCart" class="bbackInOfferBox" style="margin:20px 0 0 0;">
<div class="cartCOHdr">
<div class="inlineblock" style="padding:3px 0 0 12px;">
</div>
<div class="bbInOfferBox prodPriceBGgray">
<ul class="reg15 bold">
<li class="title">Title</li>
<li class="exp">Expires</li>
<li class="val">Value</li>
<li class="keep"/>
</ul>
</div>

<!--book 1 -->
<div id="buyback_1" class="bbInOfferBox inOfferBook"> // This div tag is generating in runtime
<ul class="reg15 bold">
<li class="title">
<li class="exp">04/25/2014</li>

<li class="val">$85.00</li>

<li class="keep keepIt">
<a onclick="return BuybackToggleCart(this.parentNode.parentNode.parentNode)" href="#">
</li>
<li class="keep sellIt hide">
</ul>
</div>


<!--//book 1 -->
<!--book 2 -->
<div id="buyback_2" class="bbInOfferBox inOfferBook cartRowBGltgray"> //// This div tag is generating in runtime
<ul class="reg15 bold">
<li class="title">
<li class="exp">04/25/2014</li>
<li class="val">$83.75</li>  // I need this li tag value
<li class="keep keepIt">
<li class="keep sellIt hide">
</ul>
</div>
<!--//book 2 -->
</div>

Thanks
Sumit Mishra
ScreenShot.png

Wojtek R

unread,
Mar 26, 2014, 9:04:50 AM3/26/14
to seleniu...@googlegroups.com
Try this code:

        double sum = 0;
        List<WebElement> elem = driver.findElements(By.xpath("//div[@id='inOfferCart']//li[@class='val'][contains(.,'$')]"));
        for (Iterator<WebElement> iterator = elem.iterator(); iterator.hasNext();) {
            WebElement webElement = (WebElement) iterator.next();
            String value = webElement.getText().substring(1);
            System.out.println("Row value:"+value);   
            sum +=Double.parseDouble(value);               
        }
        System.out.println("Sum of values="+sum);

Sumit Mishra

unread,
Mar 27, 2014, 12:14:25 AM3/27/14
to seleniu...@googlegroups.com

Hello,

Any one can help me ?

Phanindra Chowdary Chunduri

unread,
Mar 27, 2014, 12:33:36 AM3/27/14
to seleniu...@googlegroups.com
 
List<WebElement> dynamicDivs = driver.findElements(By.xpath("//div[starts-with(@id,'buyback')]"));
        for(int i=0; i< dynamicDivs.size();i++){
           
            WebElement price = dynamicDivs.get(i).findElement(By.className("val"));
            System.out.println(price.getText());
           
           
        }

Try this code.

Sumit Mishra

unread,
Mar 27, 2014, 2:04:41 AM3/27/14
to seleniu...@googlegroups.com
Hello Phanindra,

This code is working. Thank you so much !


Thanks and Regards
Sumit Mishra
Software Engineer.
Innodata India Pvt. Ltd.
C-25, 7th Floor, Stellar IT Park,
Sector-62, Noida, India.

Phone(M): +91 9213763438, +91 9899384187



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/383a5944-b753-436c-b7b3-8bc2f338db8b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages