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?
How to show the equivalence between the regularized regression and their constraint formulas using KKT
How much of data wrangling is a data scientist's job?
Were any external disk drives stacked vertically?
In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?
Is it possible to download Internet Explorer on my Mac running OS X El Capitan?
Etiquette around loan refinance - decision is going to cost first broker a lot of money
Is "remove commented out code" correct English?
Today is the Center
How do conventional missiles fly?
What killed these X2 caps?
Theorems that impeded progress
What's the difference between 'rename' and 'mv'?
Can I use a neutral wire from another outlet to repair a broken neutral?
Emailing HOD to enhance faculty application
How can I make my BBEG immortal short of making them a Lich or Vampire?
Stopping power of mountain vs road bike
Why do I get two different answers for this counting problem?
How do I write bicross product symbols in latex?
prove that the matrix A is diagonalizable
What does it mean to describe someone as a butt steak?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Does a druid starting with a bow start with no arrows?
What to put in ESTA if staying in US for a few days before going on to Canada
What is going on with Captain Marvel's blood colour?
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?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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
46.5k134790
46.5k134790
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
46.5k134790
46.5k134790
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