4

I'm trying to automate a very short sequence in a web application developped using ICEFaces. I need to click on a button which is coded as

<input type="image" title="Unterbrechen" style="padding: 3px;" 
src="../resources/images/icons/pause_square_red_24.png" 
onfocus="setFocus(this.id);" onclick="iceSubmit(form,this,event);return false;"
onblur="setFocus('');" name="formGOC:j_id52:0:j_id5330" 
id="formGOC:j_id52:0:j_id5330" class="iceCmdBtn">

But on the next call, the same button is coded as follows:

<input type="image" title="Unterbrechen" style="padding: 3px;" 
src="../resources/images/icons/pause_square_red_24.png" 
onfocus="setFocus(this.id);" onclick="iceSubmit(form,this,event);return false;" 
onblur="setFocus('');" name="formGOC:j_id52:0:j_id6813" 
id="formGOC:j_id52:0:j_id6813" class="iceCmdBtn">

The name and id have changed:

id="formGOC:j_id52:0:j_id5330"

to

id="formGOC:j_id52:0:j_id6813"

Of course, all the ancestor elements change their names and ids in the same pattern too.

How can I reliably identify this button and define a locator for this element in selenium?

Thanks for your help!

  • 1
    If you are still unable to figure it out from the article that user1316 suggests, post more of the html so we can see how the ancestors change as well and I could probably help you figure out some xpath to use. Alternatively, is the title unique? Does it change? You may be able to use it. – Sam Woods Jan 27 '12 at 17:52
  • I'll check that out - didn't have the time yet... sorry – Oli Feb 2 '12 at 8:00
5

Here is a link from good old stack overflow wherein a similar issue has been discussed/answered. Hope it helps.

1

There are a lot of ways to identify an element, and it depends on the structure of the application in question. In your case, the id is dynamic. But, I notice a few things that are not dynamic:

  • All attributes except for id and name
  • id and name's prefix ("formGOC:j_id52:0:j_id")

Also, is it possible that this is located in a known XPATH location? Maybe it's a child element of another element whose id is deterministic. In that case, you could write an XPATH such as:

//div[@id='foo']/input[startswith(@id, 'formGOC:j_id52:0:j_id')]'
0

You can use xpath to locate the element.

If you add Firepath to Firefox it will give different code for eache component. you can download it from here: https://addons.mozilla.org/en-US/firefox/addon/firepath/

This link may help you: http://diveintotesting.com/2013/02/21/web-page-object-identification-using-firebug-and-firepath/

  • Thanks for your suggestion. The problem is, that the names and ids change, so I don't know how to find them in the first place. I left the project in the meantime before I could try to use comments or hidden fields to add some metadata. – Oli Jul 29 '13 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.