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>
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.
Comments