2

I have the following HTML

<div class="t-beaneditor-row">
    <label>Login ID</label>
    SeleniumReset
</div>

I want to retrieve the string "SeleniumReset" from the HTML using WebDriver Java. I have tried

driver.findElement(By.xpath("//div")).getText()

but it is giving me "Login ID SeleniumReset". How to I retrieve "SeleniumReset" only?

Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
CodeHelp
  • 1,328
  • 5
  • 21
  • 37

1 Answers1

7

I doubt if this is possible in Selenium WebDriver.

Similar posts here:

So in your case, something like (untested pseudo Java code):

String divText = driver.findElement(By.xpath("//div")).getText();
String labelText = driver.findElement(By.xpath("//div/label")).getText();
divText.replace(labelText, "").trim();
Community
  • 1
  • 1
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • 1
    +1, and as for the problem itself, well, if you get the element's text in JS directly, you'll see the same issue: `document.getElementsByClassName("t-beaneditor-row")[0].innerText;` ....thus this is not a Selenium issue (directly, anyway). – Arran Jul 05 '13 at 10:01