Capturing elements inside a div class
up vote
2
down vote
favorite
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 html 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. I hope this make sense, any help would be very much appreciated as I am overwhelmed right now and not sure where to start.
java arrays selenium selenium-webdriver webdriver
New contributor
add a comment |
up vote
2
down vote
favorite
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 html 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. I hope this make sense, any help would be very much appreciated as I am overwhelmed right now and not sure where to start.
java arrays selenium selenium-webdriver webdriver
New contributor
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
1
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 html 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. I hope this make sense, any help would be very much appreciated as I am overwhelmed right now and not sure where to start.
java arrays selenium selenium-webdriver webdriver
New contributor
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 html 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. I hope this make sense, any help would be very much appreciated as I am overwhelmed right now and not sure where to start.
java arrays selenium selenium-webdriver webdriver
java arrays selenium selenium-webdriver webdriver
New contributor
New contributor
edited yesterday
Flimzy
36.1k96496
36.1k96496
New contributor
asked yesterday
Ajit
111
111
New contributor
New contributor
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
1
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday
add a comment |
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
1
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
1
1
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
you can make logic like this,
List<IWebElement> elements= driver.findElements(By.XPath("*//div[data-renderertype]"));
or
List<IWebElement> elements= driver.findElements(By.XPath("*[data-renderertype]"));
or
List<IWebElement> elements = driver.findElements(By.XPath("*//div[starts-with(@id,'module')]"));
forEach(IWebElement ein elements){
string str = e.getAttribute("data-renderertype");
}
add a comment |
up vote
0
down vote
Try this:
List<WebElement> allRows = driver.findElements(By.cssSelector("#zone_body > div.row"));
for( WebElement elem : allRows ){
System.out.println("Value=== " + elem.getAttribute("data-renderertype"));
}
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
add a comment |
up vote
0
down vote
What I would do is :
- Get item using
List<WebElement> divs = driver.findElements(By.xpath("#zone_body .row"))
(note that your XPath needs to be chosen carefully for the sake of your Selenium script stability and maintainability) - Stream over the list and use
WebElement.getAttribute("data-renderertype")
for each element, populating your new list or map or whatever data type you would want.
add a comment |
up vote
0
down vote
List<WebElement> elements = driver.findElements(by.xpath("//section[@id='zone_body']//div[@class='row']"));
for(int i=0;i<elements.size();i++) {
System.out.println( elements.get(i).getAttribute("data-renderertype"));
}
This snippet gets all the <div class='row'/>
elements under <section id='zone_body' />
tag into elements list, iterating the list with a for loop to get the attribute data-renderertype's value.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
you can make logic like this,
List<IWebElement> elements= driver.findElements(By.XPath("*//div[data-renderertype]"));
or
List<IWebElement> elements= driver.findElements(By.XPath("*[data-renderertype]"));
or
List<IWebElement> elements = driver.findElements(By.XPath("*//div[starts-with(@id,'module')]"));
forEach(IWebElement ein elements){
string str = e.getAttribute("data-renderertype");
}
add a comment |
up vote
0
down vote
you can make logic like this,
List<IWebElement> elements= driver.findElements(By.XPath("*//div[data-renderertype]"));
or
List<IWebElement> elements= driver.findElements(By.XPath("*[data-renderertype]"));
or
List<IWebElement> elements = driver.findElements(By.XPath("*//div[starts-with(@id,'module')]"));
forEach(IWebElement ein elements){
string str = e.getAttribute("data-renderertype");
}
add a comment |
up vote
0
down vote
up vote
0
down vote
you can make logic like this,
List<IWebElement> elements= driver.findElements(By.XPath("*//div[data-renderertype]"));
or
List<IWebElement> elements= driver.findElements(By.XPath("*[data-renderertype]"));
or
List<IWebElement> elements = driver.findElements(By.XPath("*//div[starts-with(@id,'module')]"));
forEach(IWebElement ein elements){
string str = e.getAttribute("data-renderertype");
}
you can make logic like this,
List<IWebElement> elements= driver.findElements(By.XPath("*//div[data-renderertype]"));
or
List<IWebElement> elements= driver.findElements(By.XPath("*[data-renderertype]"));
or
List<IWebElement> elements = driver.findElements(By.XPath("*//div[starts-with(@id,'module')]"));
forEach(IWebElement ein elements){
string str = e.getAttribute("data-renderertype");
}
answered yesterday
Ashish Kamble
613419
613419
add a comment |
add a comment |
up vote
0
down vote
Try this:
List<WebElement> allRows = driver.findElements(By.cssSelector("#zone_body > div.row"));
for( WebElement elem : allRows ){
System.out.println("Value=== " + elem.getAttribute("data-renderertype"));
}
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
add a comment |
up vote
0
down vote
Try this:
List<WebElement> allRows = driver.findElements(By.cssSelector("#zone_body > div.row"));
for( WebElement elem : allRows ){
System.out.println("Value=== " + elem.getAttribute("data-renderertype"));
}
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this:
List<WebElement> allRows = driver.findElements(By.cssSelector("#zone_body > div.row"));
for( WebElement elem : allRows ){
System.out.println("Value=== " + elem.getAttribute("data-renderertype"));
}
Try this:
List<WebElement> allRows = driver.findElements(By.cssSelector("#zone_body > div.row"));
for( WebElement elem : allRows ){
System.out.println("Value=== " + elem.getAttribute("data-renderertype"));
}
answered yesterday
kushal
2,0712722
2,0712722
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
add a comment |
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
This is what I got Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null Value=== null
– Ajit
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
Would you try the same code, just replace 'data-renderertype' with 'id' and share the result
– kushal
yesterday
add a comment |
up vote
0
down vote
What I would do is :
- Get item using
List<WebElement> divs = driver.findElements(By.xpath("#zone_body .row"))
(note that your XPath needs to be chosen carefully for the sake of your Selenium script stability and maintainability) - Stream over the list and use
WebElement.getAttribute("data-renderertype")
for each element, populating your new list or map or whatever data type you would want.
add a comment |
up vote
0
down vote
What I would do is :
- Get item using
List<WebElement> divs = driver.findElements(By.xpath("#zone_body .row"))
(note that your XPath needs to be chosen carefully for the sake of your Selenium script stability and maintainability) - Stream over the list and use
WebElement.getAttribute("data-renderertype")
for each element, populating your new list or map or whatever data type you would want.
add a comment |
up vote
0
down vote
up vote
0
down vote
What I would do is :
- Get item using
List<WebElement> divs = driver.findElements(By.xpath("#zone_body .row"))
(note that your XPath needs to be chosen carefully for the sake of your Selenium script stability and maintainability) - Stream over the list and use
WebElement.getAttribute("data-renderertype")
for each element, populating your new list or map or whatever data type you would want.
What I would do is :
- Get item using
List<WebElement> divs = driver.findElements(By.xpath("#zone_body .row"))
(note that your XPath needs to be chosen carefully for the sake of your Selenium script stability and maintainability) - Stream over the list and use
WebElement.getAttribute("data-renderertype")
for each element, populating your new list or map or whatever data type you would want.
answered yesterday
Vincent C.
12
12
add a comment |
add a comment |
up vote
0
down vote
List<WebElement> elements = driver.findElements(by.xpath("//section[@id='zone_body']//div[@class='row']"));
for(int i=0;i<elements.size();i++) {
System.out.println( elements.get(i).getAttribute("data-renderertype"));
}
This snippet gets all the <div class='row'/>
elements under <section id='zone_body' />
tag into elements list, iterating the list with a for loop to get the attribute data-renderertype's value.
add a comment |
up vote
0
down vote
List<WebElement> elements = driver.findElements(by.xpath("//section[@id='zone_body']//div[@class='row']"));
for(int i=0;i<elements.size();i++) {
System.out.println( elements.get(i).getAttribute("data-renderertype"));
}
This snippet gets all the <div class='row'/>
elements under <section id='zone_body' />
tag into elements list, iterating the list with a for loop to get the attribute data-renderertype's value.
add a comment |
up vote
0
down vote
up vote
0
down vote
List<WebElement> elements = driver.findElements(by.xpath("//section[@id='zone_body']//div[@class='row']"));
for(int i=0;i<elements.size();i++) {
System.out.println( elements.get(i).getAttribute("data-renderertype"));
}
This snippet gets all the <div class='row'/>
elements under <section id='zone_body' />
tag into elements list, iterating the list with a for loop to get the attribute data-renderertype's value.
List<WebElement> elements = driver.findElements(by.xpath("//section[@id='zone_body']//div[@class='row']"));
for(int i=0;i<elements.size();i++) {
System.out.println( elements.get(i).getAttribute("data-renderertype"));
}
This snippet gets all the <div class='row'/>
elements under <section id='zone_body' />
tag into elements list, iterating the list with a for loop to get the attribute data-renderertype's value.
edited yesterday
Alejandro
4,18022036
4,18022036
answered yesterday
Kasuhik Medikonda
146
146
add a comment |
add a comment |
Ajit is a new contributor. Be nice, and check out our Code of Conduct.
Ajit is a new contributor. Be nice, and check out our Code of Conduct.
Ajit is a new contributor. Be nice, and check out our Code of Conduct.
Ajit is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409324%2fcapturing-elements-inside-a-div-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do there id starts with name module always i.e. id="module......"
– Ashish Kamble
yesterday
1
Yes they are always id="module-xxxx" @AshishKamble
– Ajit
yesterday
ok then use By.XPath("*//div[starts-with(@id,'module')]")
– Ashish Kamble
yesterday
@Ajit Instead of providing a tailor-made HTML, update the question with the text based actual relevant HTML for further analysis.
– DebanjanB
yesterday