Can any one throw some ideas for the best approach for implementation of page object in the below case? - The more the ideas the better - please do write what ever you think small or big dosent matter......

I am trying to implement Page Objects for an application that has a page layout shown below.

As you can see there are 4 types of sections to the page broadly - they are cross product of {static, dynamic} and {Unique to one page, Reusable across several pages}. The challenging bit is that an user action ie click of a button, brings more UI elements to the web page and those are not a finite set and (obviously) identification mechanism of all the web elements of a particular context in such repeating sections will only differ by numbers. i.e (id = xyz_1, id=xyz_2, id=xyz_3) . (plz refer to the steps below if i have confused you). I want to reuse as much as i can of-course coz every change on UI could prove particularly very expensive if I don't.

I am using C# and we are a Microsoft shop here.

  • Clicking on "Add One More" button adds a similar section to the page and the page can grow as long indefinitely.
  • Clicking on the last "Add One More" button will add a set of sections all over again to the page.
  • Each menu item in the left pannel is either a stage in a work flow (have to go sequential one after another) or just data acquisition buckets (no mandate of previous to be complete to proceed with the next). Next and Previous buttons facilitate the movement.


3 Answers 3



What I'd do in this situation (regardless of tool) is as much as the tool permits I'd dynamically generate the Page Objects. So I'd be looking at something like this:

CurrentID = IDPattern + "_" + IterationNumber;
// xyz_$  = xyx_$ where $ is the number of the element pattern

It's a little more complicated than hard-identification but saves you from needing to repeat essentially identical test cases, and also means that you can easily add extra rounds of "Add One More" to your tests.

  • Thank you Kate. My intention was to use the FindsBy attribute of OpenQA.Selenium.Support.PageObjects. The way it provides the webelements of any webpage to the core test code made me love it. But I am not blind in that love yet so happy to give up page objects all together if some thing else make lot more sense I am using C# and that dosen't allow for the this kind of dynamism generally while defining the class properties. Were you thinking of using dynamic languages like python or ruby for this? Jun 4, 2013 at 10:18
  • I'm using C# with visual studio and dealing with dynamic items myself, actually. The method I described in my answer is one that I use for dynamically generated items: as long as there's something unique I can use to get a handle on it - or a unique parent that can be used and then a combination of other properties - it doesn't matter what the language is.
    – Kate Paulk
    Jun 4, 2013 at 11:43
  • Could you please provide some code that shows how exactly the pageObjects are generated dynamically based on the input provided. I can understand that concatenation part but I cant understand how the pageobject is changing. Some code will be really helpful. Jun 4, 2013 at 14:38

Often times on extremely dynamic pages, I don't simply have a list of elements in my page object, instead I will implement helper functions that will interact with the dynamic data/elements on the page. For example, if there you are testing an e-mail inbox instead of creating elements for message1, message2, message3, etc instead I would implement a function called SelectMessage which would take a string with the message subject or an integer with the index of the message I want to select. I may also create a function called GetMessageDetails that would return all of the details about the message that again would take either subject string or index.

If this doesn't fully answer your question let me know and I can provide more details, I deal with this all the time.

  • Thank you Sam. The repeating sections in wireframe are actually quite lengthy. Think an average of 15 web elements per section that test code would have to interact with. Don't you think, by using helper methods I would endup with too many methods in one class (PageObject) each of which would only fetch a webelement? Also wouldn't test code become a little murky to Call a method to collect that web element into another IWebElement & then do all the other operations on it each time - Or have i totally misunderstood what you suggested?! yes please provide more details - would be very helpful. Jun 4, 2013 at 10:31

Like Sam said, building a full page object for it may be more effort than it's worth. In tests I've done with a lot of dynamic content, I'll use context clues to move around the page instead of trying to point to a specific element by ID. For example, if I want to add a new entry into a table, then click the edit button for that entry, the test would add the entry, go to the table (whose element ID I know) and look through the rows for the element I created. Alternatively I can just go to the last row in the table if I'm confident it will be the last. Then I can look for through the button elements in that row for the "Edit" button and initiate a click.

The downside is that this is a lot more work for the test application to do, so it definitely adds time for the tests to run, so you want to be careful with it.

I hope that helps.

  • Hmmm got the idea but I am afraid to depend on any such patterns (added in the end, edit in the top) because different contexts will demand to depend on different patterns and soon I might end up with organic chemistry in the code (My definition of Organic Chemistry: There are nice rules that make your life easy but with 100 exceptions and 100 reasons for all those exception and its pain in the rear to remember those 100 reasons). The BAU team would be upset if I told them anything like that for the maintaining the test code. Jun 4, 2013 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.