Skip to Content
Ok last time I promised some hints and tips so lets begin. I’m going to keep the hints and tips posts fairly short in the hope it will encourage me to post more often. I received a comment on my last post asking how I find the ID/Name attributes of my forms so I though that would be a good place to start. TOP TIP – How to find ID/Name attributes of a formTo save me having to sifting through the html code of a page for the ID/Name of a control I use the FireFox browser with the Web Developer Toolbar extension installed. The Web Developer Toolbar is a great time saver not only for finding out form details but it has lots of other features too, I strongly recommend you check it out.  When you have the Web Developer Toolbar installed under the Forms menu you have the Display Form Details option, simply select this option and the page will be highlighted with yellow tags showing the ID/Name attributes of each item on the form. NOTE: Forms items which are created using HTMLB do not get a static ID/Name attribute these attributes appear to be generated each time the page is created. If this is the case how do we write tests against HTMLB forms? That’s were the next top tip comes in… TOP TIP – Writing Watir test against HTMLB formsAs I mentioned above HTMLB forms do not have a static ID/Name attribute, they are generated each time the page is created so you will find your HTMLB form controls will have an ID/Name of something along the lines of “htmlb_18528_htmlb_9998_3” if you then reload the page the ID/Name attributes will have changed i.e. “htmlb_18328_htmlb_9991_1”. This means the following Watir test code would not work as each time the page reloaded the :id attribute would be different. @ie.text_field(:id, 'htmlb_18528_htmlb_9998_3').set('test me') So how do we get around this? Well the best way I have found is to use Watir’s :index parameter when accessing form controls. The :index parameter works by sequentially counting form controls from left to right top to bottom. So to set the text of the second control on the page we use the following code: @ie.text_field(:index, 2).set('test me') This is by no means an ideal solution due to the fact if you change the layout of the page your index will also change and break your tests. However I’ve been using this method for a while now and it’s never been a major problem, besides I’m not sure how else it could be done! COMING UP IN PART SIXWell that post turned out to be slightly longer than I planned, so much for keeping these tips short! Next time more of the same.
To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Thies Topp

    thank you so far for this interesting blog. Nevertheless I got some (beginner) questions:

    a) after an assertion failed the code stops. I’d like to know how can I perform several assertions in one test method without beeing stoped due to one fail

    b)How can I navigate through the Portal navigation. Which “buttons” I hvae to click

    c)I’d like to open first a Browser and login (as you described) but then I want to use the open Portal for several tests. How can I use the used Variable @ie in several tests? I dont want to open a new window for each test

    d) How can I check the content of an iView in the Portal or even the name of an iView

    e) After I went through your example I didn’t get the teardown method to work properly: I got the error:

    Loaded suite test1Started

    W,   WARN — : frame error in waitdocumentThies Topp

    1. Justin Ramel Post author

      Just one or two questions then! I’ll do my best…

      a) Sorry as far as I know a failed assert causes the tests to stop.

      b) Portal navigation is tricky due to the number of frames the portal uses. I use the direct URL of the PAR file I am testing to avoid frame problems.

      c) @ie has a method called goto which you can use to move to a different URL this can be called as many times as you like. To use simply @ie.goto(‘‘)

      d) My next blog post will have a tip on how to find the direct URL of the PAR file you wish to test.

      e) A wild guess at the error looks like your login page is in frame. If you use the direct URL of the login page without the frame you should not get this error.

      Hope that helps!


  2. Thies Topp
    according the @ie.goto

    I try to clearify:
    def setup
    @ie =

    def test_login


    def test_2

    If I use this code, 2 IE are opened (in a row). I just want to open one. Problem the setup is done before each test. 
    If I use @ie = just in the first test it is not global and from the second test I am not able to jump to this variable.

    So as I understand you ther are two possibilities:
    1)Do everything in one test and this stopps as soon as an error occurs and you don’t know how many errors are still there
    2) Do several test but each with its own browser window


Leave a Reply