Yup:

xpath=(//input[starts-with(@id,'firstName')])[2]

Or as a utility function:

String field(String id, int instance) {
   return String.format("xpath=(//input[starts-with(@id,'%s')])[%d]", id, 
instance);
}

You can make that more general, as per my previous e-mail, by selecting an 
input or a textarea or a select.  xpath is a 1-based language, so the second 
instance is 2. If you prefer to keep your code consistent with 0-based java, 
you could do that easily, as well...

Robert

On Jan 21, 2011, at 1/213:01 PM , Mark wrote:

> On Fri, Jan 21, 2011 at 2:27 PM, Thiago H. de Paula Figueiredo
> <thiag...@gmail.com> wrote:
>> On Fri, 21 Jan 2011 17:50:30 -0200, Mark <mark-li...@xeric.net> wrote:
>> 
>>> However, I'm running into a problem with Selenium testing because the
>>> fields get ids like: firstName_12da594667a
>>> and of course it is different each time. This is causing problems
>>> because I can't test it with Selenium.
>> 
>> You can still do that. Just use XPath and the name or class attributes
>> instead of the id.
> 
> Ok the problem is that there is more than one field with the same
> name.  Something like this:
> 
> <ajaxloop>
>  <beaneditor>
>       [firstname] [lastname]
>  </beaneditor>
>  <beaneditor>
>       [firstname] [lastname]
>  </beaneditor>
>  <beaneditor>
>       [firstname] [lastname]
>  </beaneditor>
>  <beaneditor>
>       [firstname] [lastname]
>  </beaneditor>
> </ajaxloop>
> 
> The name attribute of the input boxes are the same as the id.  There
> doesn't appear to be a way to set the class since it is being
> generated by the beaneditor.
> 
> Is there a way to tell XPath to:
> 
> select the second text field that has a name that matches "firstName*"'
> 
> If so, I guess I need to dig deeper on the XPath side of things.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to