How do I get the text from the li tagGetting text from a nodeHow to get a single text node in Selenium WebDriverHow to get text from input tag?Unable to get Text from a Span tag in WebDriverSelenium java code: How to read text from hidden element that contain many tagsHow to get 'translate' text value from an Angular tag using selenium JavaUnable to retrieve the text inside the div tag even when the tag is identifiedNot able to get text which is not inside any tag Using seleniumHow to get the text from the <text> tag using seleniumhow to get text under p tag ignoring inner span tag text using java seleniumget text from textarea tag
Are the players on the same team as the DM?
What would be the challenges to taking off and landing a typical passenger jet at FL300?
Examples of topos that are not ordinary spaces
How to determine car loan length as a function of how long I plan to keep a car
Algorithms vs LP or MIP
I don't have the theoretical background in my PhD topic. I can't justify getting the degree
Ensuring all network services on a device use strong TLS cipher suites
Prove your innocence
How do I, an introvert, communicate to my friend and only colleague, an extrovert, that I want to spend my scheduled breaks without them?
Is it possible to generate a leveled character in borderlands 2?
You have 3 cakes. Everytime you eat one, there's 17% chance the number of cakes is reset to 3. Find average number of cakes eaten?
Why isn't "I've" a proper response?
How do you harvest carrots in creative mode?
Is there any music source code for sound chips?
Nothing like a good ol' game of ModTen
The Knight's estate
Pythagorean triple with hypotenuse a power of 2
Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?
Is a player able to change alignment midway through an adventure?
Are modern clipless shoes and pedals that much better than toe clips and straps?
What is a CirKle Word™?
How much authority do teachers get from *In Loco Parentis*?
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
An interview question: What's the number of String objects being created?
How do I get the text from the li tag
Getting text from a nodeHow to get a single text node in Selenium WebDriverHow to get text from input tag?Unable to get Text from a Span tag in WebDriverSelenium java code: How to read text from hidden element that contain many tagsHow to get 'translate' text value from an Angular tag using selenium JavaUnable to retrieve the text inside the div tag even when the tag is identifiedNot able to get text which is not inside any tag Using seleniumHow to get the text from the <text> tag using seleniumhow to get text under p tag ignoring inner span tag text using java seleniumget text from textarea tag
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
selenium-webdriver
add a comment |
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
selenium-webdriver
1
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
2
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03
add a comment |
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
selenium-webdriver
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
selenium-webdriver
selenium-webdriver
edited Mar 27 at 17:34
Jason Aller
3,23710 gold badges32 silver badges33 bronze badges
3,23710 gold badges32 silver badges33 bronze badges
asked Mar 27 at 15:57
vdhanorkarvdhanorkar
12 bronze badges
12 bronze badges
1
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
2
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03
add a comment |
1
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
2
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03
1
1
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
2
2
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03
add a comment |
2 Answers
2
active
oldest
votes
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] ">","<");
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
add a comment |
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child)
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
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%2f55381534%2fhow-do-i-get-the-text-from-the-li-tag%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
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] ">","<");
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
add a comment |
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] ">","<");
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
add a comment |
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] ">","<");
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] ">","<");
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
answered Mar 27 at 18:29
SlightlyKosumiSlightlyKosumi
1864 silver badges16 bronze badges
1864 silver badges16 bronze badges
add a comment |
add a comment |
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child)
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
add a comment |
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child)
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
add a comment |
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child)
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child)
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
answered Mar 28 at 0:02
supputurisupputuri
6,3402 gold badges8 silver badges24 bronze badges
6,3402 gold badges8 silver badges24 bronze badges
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%2f55381534%2fhow-do-i-get-the-text-from-the-li-tag%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
1
Can you please provide the html and your code ?
– Pritam Maske
Mar 27 at 16:19
2
Possible duplicate of Getting text from a node
– SiKing
Mar 27 at 19:23
Update the question with a bit more of the outerHTML
– DebanjanB
Mar 28 at 8:03