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!
-
1If 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– Sam Woods2012年01月27日 17:52:49 +00:00Commented Jan 27, 2012 at 17:52
-
I'll check that out - didn't have the time yet... sorryOli– Oli2012年02月02日 08:00:51 +00:00Commented Feb 2, 2012 at 8:00
3 Answers 3
Here is a link from good old stack overflow wherein a similar issue has been discussed/answered. Hope it helps.
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')]'
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– Oli2013年07月29日 18:46:03 +00:00Commented Jul 29, 2013 at 18:46
Explore related questions
See similar questions with these tags.