views:

537

answers:

5

I'm trying to capture the id of an element that will be randomly generated. I can successfully capture the value of my element id like this...

| storeAttribute | //div[1]@id | variableName |

Now my variable will be something like...

divElement-12345

I want to remove 'divElement-' so that the variable I am left with is '12345' so that I can use it later to select the 'form-12345' element associated with it...something like this:

| type | //tr[@id='form-${variableName}']/td/form/fieldset/p[1]/input | Type this |

How might I be able to accomplish this?

+1  A: 

There are many functions in XPATH which should solve your problem. Assuming "divElement-" is a constant that will not change and that you are using XPath 2.0, I would suggest:

substring-after(div[1]/@id/text(),"divElement-")

Tirno
I tried every variation of this that I could think of, but I couldn't get this to work. I don't think Selenium supports XPath 2.0. =/
Andrew
+3  A: 

You have two options in Selenium, XPath and CSS Selector. I have read that CSS Selector is better for doing tests in both FireFox and IE. Using the latest version of Selenium IDE (3/5/2009) I've had success with using storeEval which evaluates Javascript expressions, giving you access to javascript string functions.

XPath:

storeAttribute | //div[1]@id                                            | divID
storeEval      | '${divID}'.replace("divElement-", "")                  | number
type           | //tr[@id='form-${number}']/td/form/fieldset/p[1]/input | Type this

CSS Selector:

storeAttribute | css=div[1]@id                                                     | divID
storeEval      | '${divID}'.replace("divElement-", "")                             | number
type           | css=tr[id='form-${number}'] > td > form > fieldset > p[1] > input | Type this
s_hewitt
works perfect! thank you!!!
Andrew
I'd also recommend that if you are trying to do this level of complexity with your scripts, you seriously consider using Selenium RC.
Patrick Lightbody
A: 

its really very cool gr

kool
wow gr8 how u did it gr8
kool
A: 

How can I capture this?

kool
A: 

Adding comment is very fine

kool