Display results as :
Advanced Search

Go down
Posts : 1
Join date : 2012-01-22

Dynamic element id's in WebDriver

on Sun Jan 22, 2012 7:08 pm

Recently i started learing WebDriver as my client that i am working
for is planning to use webdriver for automating the web applications.
I have a doubt regarding how webdriver locates the elements on webpage
whose id's are dynamically changing (like changing for every login to
application). Can any one explain me how we can accomplish this task
with Webdriver?

Your help will be greatly appreciated!!
Thanks in Advance!!!
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: Dynamic element id's in WebDriver

on Mon Jan 23, 2012 2:25 pm
You don't need to use identifier to locate an element. There are also other ways to do it. Read THIS article.
Posts : 38
Join date : 2011-10-13

Re: Dynamic element id's in WebDriver

on Tue Jan 24, 2012 7:45 am
Following are few XPath patterns one can use to find dynamic ids.

Not yet written - locate elements based on the text content of the node.

Many sites use dynamic values for element’s id attributes, which can make them difficult to locate. One simple solution is to use XPath functions and base the location on what you do know about the element. For example, if your dynamic ids have the format (input id="text-12345") where 12345 is a dynamic number you could use the following XPath: //input[starts-with(@id, 'text-')]

If an element can be located by a value that could be surrounded by other text, the contains function can be used. To demonstrate, the element can be located based on the ‘heading’ class without having to couple it with the ‘top’ and ‘bold’ classes using the following XPath: //span[contains(@class, 'heading')]. Incidentally, this would be much neater (and probably faster) using the CSS locator strategy css=span.heading

Not yet written - locate elements based on their siblings. Useful for forms and tables.

Starting to use CSS instead of XPATH
Locating elements based on class
In order to locate an element based on associated class in XPath you must consider that the element could have multiple classes and defined in any order. However with CSS locators this is much simpler (and faster).

XPath: //div[contains(@class, 'article-heading')]
CSS: css=div.article-heading

Last edited by qappbc on Tue Jan 24, 2012 7:46 am; edited 1 time in total (Reason for editing : display formatting)
Sponsored content

Re: Dynamic element id's in WebDriver

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