3

I'm trying to select an anchor element by first containing the text "To Be Coded", then extracting a number from a string using substring, then using the greater than comparison operator (>0). This is what I have thus far:

/a[number(substring(text(),???,string-length()-1))>0] 

An example of the HTML is:

<a class="" href="javascript:submitRequest('getRec','30', '63', 'Z')"> To Be Coded&nbsp;&nbsp;(23) </a> 

My issue right now is I don't know how to find the first occurrence of the open parenthesis. I'm also not sure how to combine what I have with the contains(text(),"To Be Coded") function.

So my criteria for the selection is:

  • Must be an anchor element
  • Must include the text "To Be Coded"
  • Must contain a number greater than 0 in the parentheses

Edit: I suppose I could just "hard code" the starting position for the substring, but I'm not sure what that would be - will XPath count the white space before the text in the element? How would it handle/count the &nbsp; characters?

1
  • I think it's 1.0 - the XPath is for selenium/firefox. Commented Oct 24, 2011 at 20:03

1 Answer 1

2

Here try this :

a[contains(., 'To Be Coded') and number(substring-before(substring-after(., '('), ')')) > 0] 
Sign up to request clarification or add additional context in comments.

1 Comment

No problem. Note that this will fail if the content of the anchor has more than one parentheses.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.