0

I am using Java+HtmlUnit to test my Java-GWT project. I have an element like this:

<span unselectable="on" class="x-tree3-node-text">OCP</span>

in the source code of my generated html page.

How can I select it using XPath (or with any another method)?

I've found something like this from documentation about how to use XPath:

.getByXPath("//div[@class='x-tree3-node-text']")

But obviously it's not correct because the value "OCP" is not used anywhere.

1 Answers1

1

You are looking for a div element instead of span. Change your xpath to this:

//span[@class='x-tree3-node-text']

Furthermore if you want to find an element by its value use this xpath:

//span[text()="OCP"]
Ondrej Sotolar
  • 1,352
  • 1
  • 19
  • 29
  • As for the first: sorry, it's my typo. Yes, I used span of course. And as for the second: will this command find all the elements with text "OCP"? Because there are a lot of elements with such text, but among them I need only those which have class='x-tree3-node-text' – user2783834 Jun 08 '15 at 14:07
  • You can use both conditions with a logic operator. For what does thegetByXPath() method return you will need to look into the documentation. It might be the first element or all of them. You can always restrict the xpath search to a subtree. – Ondrej Sotolar Jun 09 '15 at 07:06