Skip to content
rahuldantalwal edited this page Apr 27, 2016 · 1 revision

In automation we have to identify locators for elements which we need to interact with. It could be ID, Name, CSS Selector, XPath or combination of all these. It is quite straight forward to identify locators for static elements which are clearly defined with static IDs. But in some applications, we come across dynamic elements and it becomes quite challenging to identify locators for such dynamic elements.

Dynamic elements are those elements which have identifiers that are dynamically generated. Dynamic identifiers are normally used for buttons, text-fields and buttons. Let us take an example of a button whose ID is in following format:- Submit-"UserName"

// Dynamic Element Locators
<button id="Submit-Rahul" />
<button id="Submit-Akash" />
<button id="Submit-Rakesh" />

In this test scenario, we can observe that element ID is not static.So, we can expect that on every script execution there will be a new ID for the element.

Generic automation framework facilitate us to handle such type of dynamic properties

**Dynamic handling**:-
* First set "UserName" variable with username in the testcase script.
* Create locater
    xpath:- //button[@id='Submit-{$UserName}']
    id   :- Submit-{$UserName}
Clone this wiki locally