Getting text from a node

0
0

I have a piece of HTML like this:

<a href="/something">
Title
<span>Author</span>
</a>

I got a WebElement that matches this HTML. How can I extract only “Title” from it? Method .getText() returns “Title\nAuthor”…

  • You must to post comments
0
0

You can’t do this in the WebDriver API, you have to do it in your code. For example:

var textOfA = theAElement.getText();
var textOfSpan = theSpanElement.getText();
var text = textOfA.substr(0, textOfA.length - textOfSpan.length).trim('\n');

Note that the trailing newline is actually part of the text of the <a> element, so if you don’t want it, you need to strip it.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website