Dave
Dave

Reputation: 27

issue accessing a text using xpath

I'm trying to find Approvals in the following html and cant seem to get it. I've tried:

  1. //td[*/text()='Approvals']
  2. //td[contains(@class, 'Approvals')]

any help would be appreciated

<td class="ThemeGrayMainItem" name="cmSubMenuID4" 
    onmouseup="cmItemMouseUp (this,1,'cmSubMenuID4',0,32)"
    onmouseout="cmItemMouseOut (this,1,'cmSubMenuID4',0,32)"
    onmousedown="cmItemMouseDown (this,1,'cmSubMenuID4',0,32)"
    onmouseover="cmItemMouseOverOpenSub (this,1,'cmSubMenuID4',0,32)">Approvals&nbsp;
</td>

Upvotes: 0

Views: 50

Answers (2)

CynicalBiker
CynicalBiker

Reputation: 609

I would use the following xpath:

//td[contains(text(),'Approvals')]

or if you wanted to be more specific:

//td[@class='ThemeGrayMainItem'][contains(text(),'Approvals')]

Upvotes: 0

alecxe
alecxe

Reputation: 473873

You may use contains():

//td[contains(., 'Approvals')]

where . refers to the element's text.

You can also apply additional checks, for instance, on the class name:

//td[@class='ThemeGrayMainItem' and contains(., 'Approvals')]

Upvotes: 1

Related Questions