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.










share|improve this question









New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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

















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.










share|improve this question









New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















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.










share|improve this question









New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Flimzy

36.1k96496




36.1k96496






New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Ajit

111




111




New contributor




Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ajit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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








  • 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














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");
}





share|improve this answer




























    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"));
    }





    share|improve this answer





















    • 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


















    up vote
    0
    down vote













    What I would do is :




    1. 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)

    2. 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.






    share|improve this answer




























      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.






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });






        Ajit is a new contributor. Be nice, and check out our Code of Conduct.










         

        draft saved


        draft discarded


















        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

























        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");
        }





        share|improve this answer

























          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");
          }





          share|improve this answer























            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");
            }





            share|improve this answer












            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");
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            Ashish Kamble

            613419




            613419
























                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"));
                }





                share|improve this answer





















                • 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















                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"));
                }





                share|improve this answer





















                • 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













                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"));
                }





                share|improve this answer












                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"));
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                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


















                • 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










                up vote
                0
                down vote













                What I would do is :




                1. 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)

                2. 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.






                share|improve this answer

























                  up vote
                  0
                  down vote













                  What I would do is :




                  1. 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)

                  2. 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.






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    What I would do is :




                    1. 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)

                    2. 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.






                    share|improve this answer












                    What I would do is :




                    1. 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)

                    2. 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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    Vincent C.

                    12




                    12






















                        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.






                        share|improve this answer



























                          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.






                          share|improve this answer

























                            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.






                            share|improve this answer














                            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.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited yesterday









                            Alejandro

                            4,18022036




                            4,18022036










                            answered yesterday









                            Kasuhik Medikonda

                            146




                            146






















                                Ajit is a new contributor. Be nice, and check out our Code of Conduct.










                                 

                                draft saved


                                draft discarded


















                                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.















                                 


                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                                Calculate evaluation metrics using cross_val_predict sklearn

                                Insert data from modal to MySQL (multiple modal on website)