Display results as :
Advanced Search

Go down
Posts : 2
Join date : 2010-01-18

Locating dynamic IDs generated when a new Directory is created !

on Mon Jan 18, 2010 4:20 pm
Dear Community,

i'm Selenium Beginner and got a Problem.

I began reading and using Selenium before 2 weeks and was amazed how much possibilities can be realizied with Selenium. But now i don't get on.

My Situation:

I want to test a ajax-based Website. On this website exists a document management system, where every user can upload his files and every user can create a new directory, which can be locked, unlocked and deleted. Every time you create a new directory, it get a dynamic or automatic generated id...and that's the problem. When i record a test case and create a new directory i can only verify the name ( text ) of the new directory, but when i want to click on the drop down menue to lock or unlock the directory the element cannot be found because the ID changed.

To substantiate my problem, i wanna describe the exact advancement: i open the document management website and click on the button: " create " a new directory --> a new site opens --> the i type the name of the new directory in the for it foreseen text field --> then i clickAndWait at the " create " - Button--> the current site is closed and we get back to the site, where we can create new directories --> now the new directory appears in the list --> now i go with the mouse on a special field at the directory and a drop down menue appears and i click at " lock " --> now i stop recording and delete the directory --> now i'm start the record from selenium --> selenium can create the new directory and i can also verify the textpresent " Selenium Test " <-- ( the name of the new directory ) but Selenium can't find the "lock" - button or " lock " ID because it has been allocated a new generated ID ...

This is my problem, how can i qualify the path of the "lock" button ?

I would be glad if somebody could help me Smile

Thanks a lot!


(PS: Sorry for my bad english, i'm not a native american, i'm from germany )
Posts : 387
Join date : 2009-07-30
Location : India

Re: Locating dynamic IDs generated when a new Directory is created !

on Tue Jan 19, 2010 12:00 pm

In selenium you can click on number of different ways.It's not necessary to click the locator on the basis of ID. You can also click on object on the basis of name


click | link=directoryName


Here are different ways:

Element Locators tell Selenium which HTML element a command refers to. The format of a locator is:


We support the following strategies for locating elements:

Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.)
Select the element with the specified @id attribute.
Select the first element with the specified @name attribute.

* username
* name=username

The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.

* name=flavour value=chocolate

Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".

* dom=document.forms['myForm'].myDropdown
* dom=document.images[56]

Locate an element using an XPath expression.

* xpath=//img[@alt='The image alt text']
* xpath=//table[@id='table1']//tr[4]/td[2]

Select the link (anchor) element which contains text matching the specified pattern.

* link=The link text

Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.

* css=a[href="#id3"]
* css=span#firstChild + span

Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

Without an explicit locator prefix, Selenium uses the following default strategies:

* dom, for locators starting with "document."
* xpath, for locators starting with "//"
* identifier, otherwise

Hope this will help you. Best of Luck.

Posts : 2
Join date : 2010-01-18

Re: Locating dynamic IDs generated when a new Directory is created !

on Thu Jan 21, 2010 4:29 pm
Dear Adviser,

thanks a lot for you quick and detailed answer...but your description is too specific for me...i'm sorry,
maybe i need it detailed and with examples to understand it, because i've never been concerned with xpath, dom, css or something like this.

thanks and greets
Sponsored content

Re: Locating dynamic IDs generated when a new Directory is created !

Back to top
Permissions in this forum:
You cannot reply to topics in this forum