How to print the extracted texts obtained from the web page with a space delimiter using Selenium and JavaOfficial locator strategies for the webdriverComplex CSS selector for parent of active childGet an OutputStream into a StringHow do I call one constructor from another in Java?Fastest way to determine if an integer's square root is an integerHow do I create a Java string from the contents of a file?Can I add jars to maven 2 build classpath without installing them?How to get an enum value from a string value in Java?How to get value from Node in Selenium Webdriver and Print in Console?How to extract the text 209.520 within a span as per the HTML through Selenium?How to extract text from text nodes through Selenium?

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

What is the highest possible scrabble score for placing a single tile

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Is it necessary to use pronouns with the verb "essere"?

Does "he squandered his car on drink" sound natural?

The Digit Triangles

Is there a way to have vectors outlined in a Vector Plot?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Did the UK lift the requirement for registering SIM cards?

Is there any evidence that Cleopatra and Caesarion considered fleeing to India to escape the Romans?

How to preserve electronics (computers, iPads and phones) for hundreds of years

Has any country ever had 2 former presidents in jail simultaneously?

How would you translate "more" for use as an interface button?

Multiplicative persistence

Can I cause damage to electrical appliances by unplugging them when they are turned on?

What is the English pronunciation of "pain au chocolat"?

What (the heck) is a Super Worm Equinox Moon?

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

What is going on with gets(stdin) on the site coderbyte?

Why do some congregations only make noise at certain occasions of Haman?

How can ping know if my host is down

How to convince somebody that he is fit for something else, but not this job?

Why should universal income be universal?



How to print the extracted texts obtained from the web page with a space delimiter using Selenium and Java


Official locator strategies for the webdriverComplex CSS selector for parent of active childGet an OutputStream into a StringHow do I call one constructor from another in Java?Fastest way to determine if an integer's square root is an integerHow do I create a Java string from the contents of a file?Can I add jars to maven 2 build classpath without installing them?How to get an enum value from a string value in Java?How to get value from Node in Selenium Webdriver and Print in Console?How to extract the text 209.520 within a span as per the HTML through Selenium?How to extract text from text nodes through Selenium?













2















With the code String result = driver.findElement (By.id ("ulDezenas")).GetText (); I can get the result 001122334455, which is present in uldezenas.
I want to get the numbers, however separated, in this way 00 11 22 33 44 55.



I already tried the split command, but I could not, unfortunately.



HTML



<ul class="numbers diaDeSorte" id="ulDezenas">
<li>00</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>55</li>
<li>66</li>
</ul>









share|improve this question




























    2















    With the code String result = driver.findElement (By.id ("ulDezenas")).GetText (); I can get the result 001122334455, which is present in uldezenas.
    I want to get the numbers, however separated, in this way 00 11 22 33 44 55.



    I already tried the split command, but I could not, unfortunately.



    HTML



    <ul class="numbers diaDeSorte" id="ulDezenas">
    <li>00</li>
    <li>11</li>
    <li>22</li>
    <li>33</li>
    <li>44</li>
    <li>55</li>
    <li>66</li>
    </ul>









    share|improve this question


























      2












      2








      2








      With the code String result = driver.findElement (By.id ("ulDezenas")).GetText (); I can get the result 001122334455, which is present in uldezenas.
      I want to get the numbers, however separated, in this way 00 11 22 33 44 55.



      I already tried the split command, but I could not, unfortunately.



      HTML



      <ul class="numbers diaDeSorte" id="ulDezenas">
      <li>00</li>
      <li>11</li>
      <li>22</li>
      <li>33</li>
      <li>44</li>
      <li>55</li>
      <li>66</li>
      </ul>









      share|improve this question
















      With the code String result = driver.findElement (By.id ("ulDezenas")).GetText (); I can get the result 001122334455, which is present in uldezenas.
      I want to get the numbers, however separated, in this way 00 11 22 33 44 55.



      I already tried the split command, but I could not, unfortunately.



      HTML



      <ul class="numbers diaDeSorte" id="ulDezenas">
      <li>00</li>
      <li>11</li>
      <li>22</li>
      <li>33</li>
      <li>44</li>
      <li>55</li>
      <li>66</li>
      </ul>






      java selenium-webdriver xpath css-selectors delimiter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 11 at 13:07









      DebanjanB

      44.8k134588




      44.8k134588










      asked Mar 7 at 23:58









      Paulo RobertoPaulo Roberto

      60511327




      60511327






















          2 Answers
          2






          active

          oldest

          votes


















          1














          To extract the numbers separately in the following fashion, 00 11 22 33 44 55 etc you need to create a List you can use either of of the elements and then use StringJoiner Class to add the space character and you can use either of the following Locator Strategies:




          • Using StringJoiner of Java 8 and later




            • Using cssSelector:



              List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              StringJoiner joiner = new StringJoiner(" ");
              for (String item : values)
              joiner.add(item.toString());
              System.out.println(joiner.toString());



            • Using xpath:



              List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              StringJoiner joiner = new StringJoiner(" ");
              for (String item : values)
              joiner.add(item.toString());
              System.out.println(joiner.toString());




          • Using Stream and Collectors of Java 9 and later



            List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
            ArrayList<String> values = new ArrayList<>();
            for(WebElement element:elementList)
            values.add(element.getText());
            System.out.println(values.stream().
            map(Object::toString).
            collect(Collectors.joining(" ")).toString());



          • Using org.apache.commons.lang3.StringUtils:



            List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
            ArrayList<String> values = new ArrayList<>();
            for(WebElement element:elementList)
            values.add(element.getText());
            System.out.println(org.apache.commons.lang3.StringUtils.join(values," "));






          share|improve this answer

























          • Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

            – Paulo Roberto
            Mar 11 at 11:51











          • @PauloRoberto Checkout my updated answer and let me know the status

            – DebanjanB
            Mar 11 at 12:17






          • 1





            It worked perfectly, thank you very much.

            – Paulo Roberto
            Mar 11 at 12:29


















          1














          Get the parent(ul) webelement first; then find elements by tag name 'li' which returns a list. Iterate over it and get the text.



          WebElement ul = driver.findElement(By.id("ulDezenas"));



           for (WebElement li : ul.findElements(By.tagName("li"))) 
          System.out.println(li.getText());






          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%2f55054733%2fhow-to-print-the-extracted-texts-obtained-from-the-web-page-with-a-space-delimit%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









            1














            To extract the numbers separately in the following fashion, 00 11 22 33 44 55 etc you need to create a List you can use either of of the elements and then use StringJoiner Class to add the space character and you can use either of the following Locator Strategies:




            • Using StringJoiner of Java 8 and later




              • Using cssSelector:



                List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());



              • Using xpath:



                List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());




            • Using Stream and Collectors of Java 9 and later



              List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(values.stream().
              map(Object::toString).
              collect(Collectors.joining(" ")).toString());



            • Using org.apache.commons.lang3.StringUtils:



              List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(org.apache.commons.lang3.StringUtils.join(values," "));






            share|improve this answer

























            • Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

              – Paulo Roberto
              Mar 11 at 11:51











            • @PauloRoberto Checkout my updated answer and let me know the status

              – DebanjanB
              Mar 11 at 12:17






            • 1





              It worked perfectly, thank you very much.

              – Paulo Roberto
              Mar 11 at 12:29















            1














            To extract the numbers separately in the following fashion, 00 11 22 33 44 55 etc you need to create a List you can use either of of the elements and then use StringJoiner Class to add the space character and you can use either of the following Locator Strategies:




            • Using StringJoiner of Java 8 and later




              • Using cssSelector:



                List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());



              • Using xpath:



                List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());




            • Using Stream and Collectors of Java 9 and later



              List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(values.stream().
              map(Object::toString).
              collect(Collectors.joining(" ")).toString());



            • Using org.apache.commons.lang3.StringUtils:



              List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(org.apache.commons.lang3.StringUtils.join(values," "));






            share|improve this answer

























            • Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

              – Paulo Roberto
              Mar 11 at 11:51











            • @PauloRoberto Checkout my updated answer and let me know the status

              – DebanjanB
              Mar 11 at 12:17






            • 1





              It worked perfectly, thank you very much.

              – Paulo Roberto
              Mar 11 at 12:29













            1












            1








            1







            To extract the numbers separately in the following fashion, 00 11 22 33 44 55 etc you need to create a List you can use either of of the elements and then use StringJoiner Class to add the space character and you can use either of the following Locator Strategies:




            • Using StringJoiner of Java 8 and later




              • Using cssSelector:



                List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());



              • Using xpath:



                List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());




            • Using Stream and Collectors of Java 9 and later



              List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(values.stream().
              map(Object::toString).
              collect(Collectors.joining(" ")).toString());



            • Using org.apache.commons.lang3.StringUtils:



              List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(org.apache.commons.lang3.StringUtils.join(values," "));






            share|improve this answer















            To extract the numbers separately in the following fashion, 00 11 22 33 44 55 etc you need to create a List you can use either of of the elements and then use StringJoiner Class to add the space character and you can use either of the following Locator Strategies:




            • Using StringJoiner of Java 8 and later




              • Using cssSelector:



                List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());



              • Using xpath:



                List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
                ArrayList<String> values = new ArrayList<>();
                for(WebElement element:elementList)
                values.add(element.getText());
                StringJoiner joiner = new StringJoiner(" ");
                for (String item : values)
                joiner.add(item.toString());
                System.out.println(joiner.toString());




            • Using Stream and Collectors of Java 9 and later



              List<WebElement> elementList = driver.findElements(By.cssSelector("ul.numbers.diaDeSorte#ulDezenas li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(values.stream().
              map(Object::toString).
              collect(Collectors.joining(" ")).toString());



            • Using org.apache.commons.lang3.StringUtils:



              List<WebElement> elementList = driver.findElements(By.xpath("//ul[@class='numbers diaDeSorte' and @id='ulDezenas']//li"));
              ArrayList<String> values = new ArrayList<>();
              for(WebElement element:elementList)
              values.add(element.getText());
              System.out.println(org.apache.commons.lang3.StringUtils.join(values," "));







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 11 at 13:28

























            answered Mar 8 at 10:07









            DebanjanBDebanjanB

            44.8k134588




            44.8k134588












            • Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

              – Paulo Roberto
              Mar 11 at 11:51











            • @PauloRoberto Checkout my updated answer and let me know the status

              – DebanjanB
              Mar 11 at 12:17






            • 1





              It worked perfectly, thank you very much.

              – Paulo Roberto
              Mar 11 at 12:29

















            • Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

              – Paulo Roberto
              Mar 11 at 11:51











            • @PauloRoberto Checkout my updated answer and let me know the status

              – DebanjanB
              Mar 11 at 12:17






            • 1





              It worked perfectly, thank you very much.

              – Paulo Roberto
              Mar 11 at 12:29
















            Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

            – Paulo Roberto
            Mar 11 at 11:51





            Result: 01 02 03 I want everyone to be on the same line and separated by 1 space 01 02 03, is it possible?

            – Paulo Roberto
            Mar 11 at 11:51













            @PauloRoberto Checkout my updated answer and let me know the status

            – DebanjanB
            Mar 11 at 12:17





            @PauloRoberto Checkout my updated answer and let me know the status

            – DebanjanB
            Mar 11 at 12:17




            1




            1





            It worked perfectly, thank you very much.

            – Paulo Roberto
            Mar 11 at 12:29





            It worked perfectly, thank you very much.

            – Paulo Roberto
            Mar 11 at 12:29













            1














            Get the parent(ul) webelement first; then find elements by tag name 'li' which returns a list. Iterate over it and get the text.



            WebElement ul = driver.findElement(By.id("ulDezenas"));



             for (WebElement li : ul.findElements(By.tagName("li"))) 
            System.out.println(li.getText());






            share|improve this answer



























              1














              Get the parent(ul) webelement first; then find elements by tag name 'li' which returns a list. Iterate over it and get the text.



              WebElement ul = driver.findElement(By.id("ulDezenas"));



               for (WebElement li : ul.findElements(By.tagName("li"))) 
              System.out.println(li.getText());






              share|improve this answer

























                1












                1








                1







                Get the parent(ul) webelement first; then find elements by tag name 'li' which returns a list. Iterate over it and get the text.



                WebElement ul = driver.findElement(By.id("ulDezenas"));



                 for (WebElement li : ul.findElements(By.tagName("li"))) 
                System.out.println(li.getText());






                share|improve this answer













                Get the parent(ul) webelement first; then find elements by tag name 'li' which returns a list. Iterate over it and get the text.



                WebElement ul = driver.findElement(By.id("ulDezenas"));



                 for (WebElement li : ul.findElements(By.tagName("li"))) 
                System.out.println(li.getText());







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 3:18









                Nikesh PNikesh P

                111




                111



























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054733%2fhow-to-print-the-extracted-texts-obtained-from-the-web-page-with-a-space-delimit%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

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived