I need to extract all id values with casperjs









up vote
-1
down vote

favorite












id = casper.evaluate(function() 
return Array.prototype.map.call(document.querySelectorAll("image"),
function(e) return e.getElementById();););

this.echo(id);









share|improve this question



























    up vote
    -1
    down vote

    favorite












    id = casper.evaluate(function() 
    return Array.prototype.map.call(document.querySelectorAll("image"),
    function(e) return e.getElementById();););

    this.echo(id);









    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      id = casper.evaluate(function() 
      return Array.prototype.map.call(document.querySelectorAll("image"),
      function(e) return e.getElementById();););

      this.echo(id);









      share|improve this question















      id = casper.evaluate(function() 
      return Array.prototype.map.call(document.querySelectorAll("image"),
      function(e) return e.getElementById();););

      this.echo(id);






      javascript casperjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 3:21









      Cœur

      17.3k9102142




      17.3k9102142










      asked May 12 '17 at 7:43









      Javier Sega

      447




      447






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          --Update--



          If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for.



          Example:



          var casper = require('casper').create();
          var ids = ;

          function getIdsByClassValue()
          // use your selector here eg. '.image'.
          var elems = document.querySelectorAll('input[type="submit"]');
          return Array.prototype.map.call(elems, function (e)
          // change to the attribute you are looking for.
          return e.getAttribute('value')
          );


          casper.start('https://www.google.com/');

          casper.then(function ()
          ids = this.evaluate(getIdsByClassValue);
          );

          casper.run(function()
          this.echo('n - ' + ids.join('n - ')).exit();
          );


          You can use getElementsAttribute to do that.




          .getElementsAttribute



          Signature: getElementsAttribute(String selector, String attribute)



          Retrieves the values of an attribute on each element matching the provided selector:




          Here is an example.



          var ids = ;

          var casper = require('casper').create();

          casper.start('https://google.com/', function()
          this.wait(1000, function()
          ids = this.getElementsAttribute('*', 'id')
          .filter(function(id)
          return id.length > 0;
          )
          );
          );

          casper.then( function()
          this.echo('n - ' + ids.join('n - ')).exit();
          )

          casper.run();





          share|improve this answer






















          • I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
            – Javier Sega
            May 12 '17 at 11:07










          • I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
            – DavidDomain
            May 12 '17 at 12:54

















          up vote
          0
          down vote













          return e.getElementById(); does obviously not make any sense, because getElementById is a function that expect one argument and is only available on the document.



          It seems you want to return the id property:



          var ids = casper.evaluate(function() 
          return Array.prototype.map.call(document.querySelectorAll("image"), function(e)
          return e.id;
          );
          );

          this.echo(ids);





          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',
            autoActivateHeartbeat: false,
            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
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43932139%2fi-need-to-extract-all-id-values-with-casperjs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            --Update--



            If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for.



            Example:



            var casper = require('casper').create();
            var ids = ;

            function getIdsByClassValue()
            // use your selector here eg. '.image'.
            var elems = document.querySelectorAll('input[type="submit"]');
            return Array.prototype.map.call(elems, function (e)
            // change to the attribute you are looking for.
            return e.getAttribute('value')
            );


            casper.start('https://www.google.com/');

            casper.then(function ()
            ids = this.evaluate(getIdsByClassValue);
            );

            casper.run(function()
            this.echo('n - ' + ids.join('n - ')).exit();
            );


            You can use getElementsAttribute to do that.




            .getElementsAttribute



            Signature: getElementsAttribute(String selector, String attribute)



            Retrieves the values of an attribute on each element matching the provided selector:




            Here is an example.



            var ids = ;

            var casper = require('casper').create();

            casper.start('https://google.com/', function()
            this.wait(1000, function()
            ids = this.getElementsAttribute('*', 'id')
            .filter(function(id)
            return id.length > 0;
            )
            );
            );

            casper.then( function()
            this.echo('n - ' + ids.join('n - ')).exit();
            )

            casper.run();





            share|improve this answer






















            • I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
              – Javier Sega
              May 12 '17 at 11:07










            • I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
              – DavidDomain
              May 12 '17 at 12:54














            up vote
            1
            down vote













            --Update--



            If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for.



            Example:



            var casper = require('casper').create();
            var ids = ;

            function getIdsByClassValue()
            // use your selector here eg. '.image'.
            var elems = document.querySelectorAll('input[type="submit"]');
            return Array.prototype.map.call(elems, function (e)
            // change to the attribute you are looking for.
            return e.getAttribute('value')
            );


            casper.start('https://www.google.com/');

            casper.then(function ()
            ids = this.evaluate(getIdsByClassValue);
            );

            casper.run(function()
            this.echo('n - ' + ids.join('n - ')).exit();
            );


            You can use getElementsAttribute to do that.




            .getElementsAttribute



            Signature: getElementsAttribute(String selector, String attribute)



            Retrieves the values of an attribute on each element matching the provided selector:




            Here is an example.



            var ids = ;

            var casper = require('casper').create();

            casper.start('https://google.com/', function()
            this.wait(1000, function()
            ids = this.getElementsAttribute('*', 'id')
            .filter(function(id)
            return id.length > 0;
            )
            );
            );

            casper.then( function()
            this.echo('n - ' + ids.join('n - ')).exit();
            )

            casper.run();





            share|improve this answer






















            • I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
              – Javier Sega
              May 12 '17 at 11:07










            • I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
              – DavidDomain
              May 12 '17 at 12:54












            up vote
            1
            down vote










            up vote
            1
            down vote









            --Update--



            If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for.



            Example:



            var casper = require('casper').create();
            var ids = ;

            function getIdsByClassValue()
            // use your selector here eg. '.image'.
            var elems = document.querySelectorAll('input[type="submit"]');
            return Array.prototype.map.call(elems, function (e)
            // change to the attribute you are looking for.
            return e.getAttribute('value')
            );


            casper.start('https://www.google.com/');

            casper.then(function ()
            ids = this.evaluate(getIdsByClassValue);
            );

            casper.run(function()
            this.echo('n - ' + ids.join('n - ')).exit();
            );


            You can use getElementsAttribute to do that.




            .getElementsAttribute



            Signature: getElementsAttribute(String selector, String attribute)



            Retrieves the values of an attribute on each element matching the provided selector:




            Here is an example.



            var ids = ;

            var casper = require('casper').create();

            casper.start('https://google.com/', function()
            this.wait(1000, function()
            ids = this.getElementsAttribute('*', 'id')
            .filter(function(id)
            return id.length > 0;
            )
            );
            );

            casper.then( function()
            this.echo('n - ' + ids.join('n - ')).exit();
            )

            casper.run();





            share|improve this answer














            --Update--



            If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for.



            Example:



            var casper = require('casper').create();
            var ids = ;

            function getIdsByClassValue()
            // use your selector here eg. '.image'.
            var elems = document.querySelectorAll('input[type="submit"]');
            return Array.prototype.map.call(elems, function (e)
            // change to the attribute you are looking for.
            return e.getAttribute('value')
            );


            casper.start('https://www.google.com/');

            casper.then(function ()
            ids = this.evaluate(getIdsByClassValue);
            );

            casper.run(function()
            this.echo('n - ' + ids.join('n - ')).exit();
            );


            You can use getElementsAttribute to do that.




            .getElementsAttribute



            Signature: getElementsAttribute(String selector, String attribute)



            Retrieves the values of an attribute on each element matching the provided selector:




            Here is an example.



            var ids = ;

            var casper = require('casper').create();

            casper.start('https://google.com/', function()
            this.wait(1000, function()
            ids = this.getElementsAttribute('*', 'id')
            .filter(function(id)
            return id.length > 0;
            )
            );
            );

            casper.then( function()
            this.echo('n - ' + ids.join('n - ')).exit();
            )

            casper.run();






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 12 '17 at 12:52

























            answered May 12 '17 at 9:21









            DavidDomain

            10.5k22042




            10.5k22042











            • I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
              – Javier Sega
              May 12 '17 at 11:07










            • I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
              – DavidDomain
              May 12 '17 at 12:54
















            • I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
              – Javier Sega
              May 12 '17 at 11:07










            • I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
              – DavidDomain
              May 12 '17 at 12:54















            I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
            – Javier Sega
            May 12 '17 at 11:07




            I want to specify by unique class name <div id = 111 class = "image"> <div id = 222 class = "image">
            – Javier Sega
            May 12 '17 at 11:07












            I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
            – DavidDomain
            May 12 '17 at 12:54




            I have made an edit. You would just have to change the querySelectorAll and pass in your css class name eg. '.image', you also want to change the getAttribute to the attribute you are looking for.
            – DavidDomain
            May 12 '17 at 12:54












            up vote
            0
            down vote













            return e.getElementById(); does obviously not make any sense, because getElementById is a function that expect one argument and is only available on the document.



            It seems you want to return the id property:



            var ids = casper.evaluate(function() 
            return Array.prototype.map.call(document.querySelectorAll("image"), function(e)
            return e.id;
            );
            );

            this.echo(ids);





            share|improve this answer
























              up vote
              0
              down vote













              return e.getElementById(); does obviously not make any sense, because getElementById is a function that expect one argument and is only available on the document.



              It seems you want to return the id property:



              var ids = casper.evaluate(function() 
              return Array.prototype.map.call(document.querySelectorAll("image"), function(e)
              return e.id;
              );
              );

              this.echo(ids);





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                return e.getElementById(); does obviously not make any sense, because getElementById is a function that expect one argument and is only available on the document.



                It seems you want to return the id property:



                var ids = casper.evaluate(function() 
                return Array.prototype.map.call(document.querySelectorAll("image"), function(e)
                return e.id;
                );
                );

                this.echo(ids);





                share|improve this answer












                return e.getElementById(); does obviously not make any sense, because getElementById is a function that expect one argument and is only available on the document.



                It seems you want to return the id property:



                var ids = casper.evaluate(function() 
                return Array.prototype.map.call(document.querySelectorAll("image"), function(e)
                return e.id;
                );
                );

                this.echo(ids);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 14 '17 at 12:48









                Artjom B.

                52.7k1779143




                52.7k1779143



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43932139%2fi-need-to-extract-all-id-values-with-casperjs%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

                    Darth Vader #20

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Ondo