0

So I have to parse HTML that is structured as such

<div>
    Hello
    <div name="DONOTWANT">
        Text that I dont want and other junk
    </div>
    World
</div>

I require a solution that would retrieve the immediate text in a block of HTML. In this example, I would want "Hello World" while ignoring all other text. Are there any suggestions as to how I can do this with webdriver and selenium? I am programming in java but, if you have a solution in another language that can be translated over, I would take that as well.

Currently if I have something like

String foo = driver.findElement(By.xpath(".//div")).getText();

foo would contain "Hello Text that I dont want and other junk World" which is less than optimal.

AlbChu
  • 135
  • 1
  • 2
  • 11
  • Maybe this Question ca help you: http://stackoverflow.com/questions/4735453/xpath-xquery-find-text-in-a-node-but-ignoring-content-of-specific-descendant – VolkerK Jun 22 '12 at 06:46

1 Answers1

0

I faced a similar problem before and I had to solve it using java script with the help of the JavascriptExecutor.

You can check this question I had asked before on this site - Reading text using selenium webdriver(xpath)

Let me know if this solves your problem.

Community
  • 1
  • 1
Hari Reddy
  • 3,808
  • 4
  • 33
  • 42