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?
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
add a comment |
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
add a comment |
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
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
java selenium-webdriver xpath css-selectors delimiter
edited Mar 11 at 13:07
DebanjanB
44.8k134588
44.8k134588
asked Mar 7 at 23:58
Paulo RobertoPaulo Roberto
60511327
60511327
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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," "));
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
add a comment |
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());
add a comment |
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
);
);
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%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
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," "));
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
add a comment |
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," "));
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
add a comment |
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," "));
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," "));
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
add a comment |
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
add a comment |
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());
add a comment |
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());
add a comment |
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());
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());
answered Mar 8 at 3:18
Nikesh PNikesh P
111
111
add a comment |
add a comment |
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.
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%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
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