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!

asked Jan 27, 2012 at 8:13
2
  • 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. Commented Jan 27, 2012 at 17:52
  • I'll check that out - didn't have the time yet... sorry Commented Feb 2, 2012 at 8:00

3 Answers 3

5

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

answered Jan 27, 2012 at 9:48
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')]'
answered Jan 27, 2012 at 20:19
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/

Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
answered Jul 29, 2013 at 13:26
1
  • 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. Commented Jul 29, 2013 at 18:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.