views:

25

answers:

1

Hi there,

I'm trying to select a sub-menu item using XPATH.

The submenu items have the following structure in common.

..../span/a[@class="button"]

Inside the anchor tag, the title of button is present inside a <strong/> tag

e.g.

<span>
<a class="button" text="" href=".....">
<strong> submenu item 1 </strong>
</a>
</span>

How do I select the anchor tag which has "submenu item 1" inside it using XPATH?

thanks in advance...

vamyip

+1  A: 

You can use the descendant predicate:

..../span/a[@class="button"][descendant::strong=" submenu item 1 "]

Note that this is sensitive to the spacing around the outside. You can normalise it, if that's a problem:

..../span/a[@class="button"][normalize-space(descendant::strong)="submenu item 1"]
Chris Smith
Thanks for your prompt reply. works exactly as required
vamyip