Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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!

share|improve this question
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

3 Answers 3

You can use xpath to locate the element. Add firepath to "firefox' it will gives different code for eache component you con downold it from her: 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/

share|improve this answer
    
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

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')]'
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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