How to extract text from child Text Nodes - Selenium

Illes

From the code below I would like to extract: "I give you €0.00.".

With the following xpath I can target it from Developer tools:

//*[@id="windowID"]/text()[2]

But using Selenium I can only look for this element with driver.findElement(By.Xpath(""))

The problem is that it says that the result of xpath expression is not an element, but an [object Text]

If I target only the ancestor div (windowID), then the whole text is received. I only want the mentioned part to be saved to a string.

<div id="windowID" class="windowClass">"Your are awesome."<br>"I give you €0.00."<br>"But you should give me €0.00."<br>"Would you like to do that?"</div>
DebanjanB

To extract the text I give you €0.00. you can use the following line of code :

IWebElement elem = driver.FindElement(By.XPath("//div[@class='windowClass' and @id='windowID']"));
string text = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].childNodes[3].textContent;", elem);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract separate text nodes with Jsoup?

How to extract text from text nodes through Selenium?

How to extract dynamic text from multiple child nodes within the html through getText()

Extract text from webpage using Selenium in Python

How to extract text from text nodes within same parent node through XPath

How to extract text from previously inserted input with Selenium?

How to extract the text elements using Selenium in Python?

How to extract text from Selenium Object?

How to extract the text $7.56 from the webpage using Selenium through Python

How i extract text from a model dialog in selenium?

How to extract the text from the HTML using Selenium and Python

How to extract text from div class using Selenium with Python

How to extract text from an unordered list with selenium

How to extract the text 5 from the text node within the parent div node using Selenium and Python

Extract and combine all text child nodes

Get text value only from NSXMLElement without the text of child nodes

Change the text from child nodes

How to get concatenated child text nodes in lxml

How to extract the text from the element using Selenium through Java

How to extract text from svg using python selenium

How to extract the text from the parent node excluding the text from the child node using Selenium

Python/Selenium - how to extract text from modal fade content?

How to extract multiple text using selenium python

Selenium Python - Extract Text from Class

How to extract the text from the webelements using Selenium and Python

How to extract the number from the parent div excluding the text of the child using Selenium IDE

How to extract text from TextNode using Selenium in VBA

Selenium - How to get the text from an element but retaining child element source

How can I extract the text from a webelement using selenium