tags:

views:

21

answers:

2

HI

lets say i have a link that can not be identified in my html page like so:

<a href="/somthing/confirm_delete_somthing?&id=12">Delete this monitor</a>

can we have a xpath repersenting the link using the Delete this monitor label?

somthing like //a[@label="Delete this monitor"]

thanks

+1  A: 

Replace @label with text() which represents a text value of a node.

//a[text()="Delete this monitor"]

For cases where the text is on another line, such as

<a>
   Delete this monitor
</a>

you can use normalize-space() function which removes starting and trailing spaces:

//a[normalize-space(text())="Delete this monitor"]

František Žiačik
that works great thanks
Mo
+1  A: 

Use:

//a[. = "Delete this monitor"]

or

//a[normalize-space() ="Delete this monitor"]

This will select the node even when it is something like the following:

<a href="/somthing/confirm_delete_somthing?&id=12">Delete <strong>this</strong> monitor</a>

In contrast, the expression from currently accepted answer does not select such a node.

Dimitre Novatchev
lets say i didnt know the end of node, i.e i know its going to start with "Delete this" but was not sure what the third word is, what do i use then? or would the 'normalize-space()' work?
Mo
@Mo: Use: `starts-with(normalize-space(), 'Delete this')`
Dimitre Novatchev