Search This Blog

Tuesday, May 18, 2010

How to identify dynamic element in selenium

Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically. Each time id gets generated differently. So to handle this situation we use some JavaScript functions.


if your dynamic element's ids have the format <button id="continue-12345" /> where 12345 is a dynamic number you could use the following

XPath: //button[starts-with(@id, 'continue-')]  


Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element <input class="top suggest business"> can be located based on the ‘suggest’ class without having to couple it with the ‘top’ and ‘business’ classes using the following

XPath: //input[contains(@class, 'suggest')].


  1. Actual problem is ,
    When i click Select tag button,xpath value changes like:
    1st time i get---->id('fpey_selectTag')
    2nd time i get---->id('dmht_selectTag')
    3rd time i got------>id('gajx_selectTag')
    so on...

    I wrote my test case as

    selenium.type("gajx_tags", "a,b,c,");
    and test failed.Please tell me what should i include in place of
    gajx_tags in above line.
    Thanks in advance

  2. Hi Farhin,
    Go through the below blogs you will get info about that .

  3. Can you please send me your html of your elements ?

  4. Hi Niraj,

    I have the situation like having multiple radio buttons with the dynamic values like radio_{x} where x is the dynamic values.The value x came from DB.

    I used the following selenium command to select the radio button., 'radio-'));

    But the problem is every time it selects the first radio button only but i need to select second and third ...etc.


  5. Then you read this post in this condition.

  6. F-202222|-2@locationName

    I want ti Replace 2 with regular expression.

  7. Problem:DropDown List:Selenium-perl
    In my application contains one dropdown box,i am unable to identify the dorpdownlist elements based on id.because it's changing every time dynamically.

    For ex:1st time:id=uki-list-1234-row-1
    2 nd time:id=uki-list-4123-row-1

    I have tried in another way to identify the id:

    like this..
    value :label=regexp:\uki-list-\d+-\row-\d?
    but i got the error Locator not found.

  8. Problem:DropDown List:Selenium-perl

    Actually "select" command is used to select the dropdown box. "selectAndWait: for selct the options in drop down box based on label reg.expressons or id's,but in my application select command is not working.there is any other commands for selecting dropdown elements. please tell me.
    My dropdown box is devloped by uki java script frame work

  9. I was very much impressed with your blog, Thanks a lot for the information.

  10. Hi i have a situation where in i need to select an item from a drop down list and click on go button which would populate next drop down list.i used select,mouseDown nothing element identifier not locating the element properly

  11. hello my case is something different here is a button in my case and its value changed every time for example first value was "CommonBucket_'ct102-'_btnHold" and second time value was "CommonBucket_'ct104-'_btnHold"... how can i solve this problem please suggest me a best solution.

    Thanks in Advance

  12. Aw, this was an exceptionally nice post. Taking the time
    and actual effort to make a superb article… but what can I say… I put things off a whole lot and don't manage to get anything done.

    My site; smile

  13. Τhank you so much for this. I'm a blogger coming from Niederelbert, Germany and what I just read here on couldn't bе wгіttеn muсh better.
    Рerusing thiѕ poѕt rеminds mе оf my old гoοmie,
    Faustino. He pегsiѕtently κept ρreаching abоut this.
    I most cеrtainly will send thіѕ
    stuff to him. Pretty sure hе wіll hаve a
    gooԁ time reаding this. I аm thankful to уou you fοr
    ѕhаring thiѕ.

    Alsо visit my webpаge :: outdoor pizza oven

  14. in xpath if input id =1234 & 1234 is dynamic, how to locate an element in selenium?

  15. this is exactly what we want

  16. HI
    I have one drop down list element. which dynamically changes every time."//div[9]/div[2]/div[3]/div[3]/select" where "div[3]/select" is constant.
    so can i identify that ? do we have ends-with function as like starts with function.

  17. there is some function called as contains similar to start with . you can use it

  18. This comment has been removed by the author.

  19. Hi,

    my $test = $driver->find_element("q" , "name");

    by using "$test" i can pass inputs to textbox, but is there any way to get "ID" of textbox using "$test".

    Please help
    Thank you

  20. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.

  21. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

  22. Thanks for sharing information about Selenium training, I read your entire post and realize that your post is really informative. Such type of post is really helpful for those people who want to learn Selenium training. Apart from this I read another informative post for same kind of information. For your further information I am sharing that informative post about Selenium training.

  23. Hi Niraj
    I have one doubt, i have one text box whose id keeps chaging below is the HTML Code
    input id="contact_type0" class="form-control ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" name="contact_type" ng-model="data.contact_type" placeholder="Contact Type" required="" aria-invalid="false" style="" type="text"/
    2nd time if i click Add New Button
    it gives me
    input id="contact_type1" class="form-control ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" name="contact_type" ng-model="data.contact_type" placeholder="Contact Type" required="" aria-invalid="false" style="" type="text"
    So i have written the xpath="//input[starts-with(@id,'contact_status')]" but works well with first time but 2nd time it fails it always identify the 1st text box, could you please tell how to write the generic xpath which will work and i am looping this code for 1st works well , in the 2nd unable to identify the 2nd text box instead it identify the first one. please help me out.

    1. I need help on same issue.Please let me know any one have soln

  24. I have read your blog its very attractive and impressive. I like your blog selenium Online Training Bangalore

  25. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    Devops Training courses
    python Training in chennai
    Devops Training in Bangalore

  26. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Advanced AWS Course Interview Questions And Answers, Top 250+AWS Jobs Interviews Questions and Answers 2018
    Advanced AWS Jobs Interview questions and answers |Best Top 110 AWS Interview Question and Answers – india

  27. I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.
    rpa training in bangalore
    rpa training in chennai
    rpa training in pune
    best rpa training in bangalore

  28. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    Best Devops Training in pune
    Devops Training in Bangalore
    Power bi training in Chennai

  29. My spouse and I love your blog and find almost all of your post’s to be just what I’m looking for. Can you offer guest writers to write content for you? I wouldn’t mind producing a post or elaborating on some the subjects you write concerning here. Again, awesome weblog!
    python Online training in chennai
    python Online training in bangalore
    python interview question and answers

  30. I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
    I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!

    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers

  31. I Read more blog with this same topic... But This blog is very clear and informative
    Best Devops Training in Chennai | Best Devops Training Institute in Chennai

  32. This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
    Python Online training
    python Course institute in Chennai
    Python Course institute in Bangalore