views:

341

answers:

3

Hi I am using Selenium RC in Eclipse and JUnit , how i capture dynamic id , Please answer me soon

A: 

To make them static isn't always possible for particular project(framework used).

You may deal with developers, that they provide rules for ID prefixes or postfixes.

And then check correspondingly with XPATH selectors and regexp.

sergionni
a framework that doesn't allow static (or predictable) ids for meaningful components should be dropped immediately.
Bozho
at least they, may try do IDs predictable
sergionni
Bozho,i haven't seen, you said "predictable", so agree with you
sergionni
@Bozho - so you suggest people shouldn't use Dojo and ExtJS? They create dynamic ids on components but can easily be caught and worked against
AutomatedTester
don't they allow you to assign ids? JSF generates ids as well, but it gives you the option to give them yourself.
Bozho
@Bozho - When you are working something that generates a lot of things before its rendered you don't always know the ID and since IDs need to be unique you need to make sure that there is no chance of overlap. So if you have 2 people called Bohzo in a list on the page and to edit their accounts you need a unique identifier.Not always doable.
AutomatedTester
I said static or _predictable_. Complex components (RichFaces for example) generate a lot of other elements. But their IDs are predictable. Like `mycomponentid_header`. Or if there are multiple elements inside they are named `mycomplnentid:1:item`, `mycomponentid:2:item` and so on.
Bozho
+3  A: 

To use work against dynamic IDs you need to either use CSS selectors or XPath.

For xpath you would have xpath=//input[@contains(@id,'partOfId')] to find an input where you know part of the ID or for css it would be css=input[id^='partOfId']

AutomatedTester
A: 

You can use static name instead. Or your own custom locator

Ula Karzelek