Question

I have a site I need to login to but one of the input text fields id and name change each time. Is there a way to access element via a regex? Thanks in advance.

Example:

id="form:wrap:j_idt1297:0:j_idt1298:input"
id="form:wrap:j_idt2151:0:j_idt2152:input"

<input class="iceInpSecrt large" 
id="form:wrap:j_idt1297:0:j_idt1298:input"    
name="form:wrap:j_idt1297:0:j_idt1298:input" 
onblur="setFocus('');" onfocus="setFocus(this.id);" 
onkeyup="iceSubmit(form,this,event);" 
onmousedown="this.focus();" tabindex="" type="password" value="">
Was it helpful?

Solution

Yes, you can match elements using regular expressions. It is similar to locating the id/name by string.

It looks like:

browser.text_field(:id => /a_regex/)

For your example, the following would locate the text field with either of the ids mentioned:

browser.text_field(:id => /form:wrap:j_idt\d{4}:0:j_idt\d{4}:input/)

Note:

  • You will need to verify that this regex will not end up also matching other elements on the page. If it does, you will need to make your search more specific by using other information about the element (perhaps the class) or information around the element (perhaps the field's label).
  • Depending on the other elements on the page, this regex might be more specific than you need. For example, perhaps just the first part is unique. In that case you could just do /form:wrap:j_idt/.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top