Capturing elements inside a div class - Selenium

409 views
Skip to first unread message

Ajit K

unread,
Nov 21, 2018, 4:18:18 AM11/21/18
to Selenium Users
hello everyone,
I am extremely new to selenium so please bare with me if I am unable to explain what I am trying to achieve. Below is the same code

<section id=“zone_body” class =“zone zone_body>

<div class =“row”>…<div>

<div data-o_id="4915279" data-renderertype="imagesonly" class="module module-carousel module-carousel--imagesonly col col--1-1" id="module-2319657">

::after

</div>

<div class =“row”>…<div>

<div class =“row”>…<div>

<div class =“row”>…<div>

<div class =“row”>…<div>

<div class =“row”>…<div>

<div class =“row”>…<div>

<div class =“row”>…<div>

</section>


I am testing a web page which I am trying to automate using selenium with Java. As per the code above every page that I am testing has this standard 16 different types of data-renderertype and as per the code above the 8 different div class inside the body can have the same or a different data-renderertype all together, e.g above has "imagesonly" and can be in any random order, What I really want to achieve is to extract all the data-renderertype values from all the 8( this is not a constant number as it can vary depending upon the page )different div class so it can be stored and used to compare it to a different version of the site when I run it against a stag or preproduction environment. I hope this make sense, any help would be very much appreciated as I am overwhelmed right now and not sure where to start.

Thanks in Advance,

A



Venu G

unread,
Nov 21, 2018, 5:12:32 AM11/21/18
to Selenium Users
Below code will help 

List<WebElement> objElm = fireFoxDriver.findElements(By.xpath("//div[@data-renderertype]"));
for(WebElement objChldElm:objElm)
{
System.out.println(objChldElm.getAttribute("data-renderertype"));
Reply all
Reply to author
Forward
0 new messages