How to loop each element in a div using Selenium Java?

34 views
Skip to first unread message

hariprasad

unread,
Nov 29, 2017, 4:02:14 AM11/29/17
to Selenium Users
Hi,

  I am trying loop through all elements in div. How can I do?


Till now I tried like below but its not working. I expect it has to print all the elements in the container_class but its printing like this


"[[[FirefoxDriver: firefox on XP (d3434gfe-d431-4e51-e6rt-a3asewc7806f)] -> xpath: id("divs_container_class")]]"


I want to print all the elements.


HTML:


<div class="container_class" id="container_id">

    <div id="1" class="1 class"></div>

    <div id="2" class="2 class"></div>

    <div id="3" class="3 class"></div>

    <div id="4" class="4 class"></div>

</div>


Java(Selenium):


List<WebElement> elementsxpath = driver.findElements(By.xpath("id(\"divs_container_class\")"));

for(int i=0; i<elementsxpath .size(); i++) 

{

    System.out.println(elementsxpath);

}


thanks

Hari

Reply all
Reply to author
Forward
0 new messages