Google Analytics


To search for specific articles you can use advanced Google features. Go to and enter "" before your search terms, e.g. CSS selectors

will search for "CSS selectors" but only on my site.

Wednesday, June 23, 2010

Understanding how xpath relates to web pages

When using automation tools like Selenium or Watij you often find yourself creating an xpath to find an element. Talking to a few people there seems to be a lack of understanding of how an xpath relates to a web page.

I think the step which is missing for most people is understanding how to look at a web page.

A web page is merely a group of blocks inside blocks. To illustrate I have the following image:

Image the outer block is the <BODY> of the web page. Inside the outer block, i.e. the BODY are two rectangles. Let's say they are <TABLE> elements. The top table, i.e. /HTML/BODY/TABLE[1], has one row and three columns. The lower table, i.e. /HTML/BODY/TABLE[2], has three rows and four columns.

Let's say that both tables have one row of cells where the class was 'foo', i.e. <TD class='foo'>. If I wanted to find all cells with class='foo' and the text contained 'bar' I would use:

    //TD[@class='foo' and contains(text(), 'bar')]

But what if I wanted to search only the second table? Then I would use:

    //TABLE[2]/TBODY/TR/TD[@class='foo' and contains(text(), 'bar')]

Essentially, the longer the xpath the small the area of the web page I am searching. Using //BODY will search the largest square in my example. Using //BODY/TABLE[2] will search the lower table or the second level in.

If you look at the third row of the lower table you can see the 'cells' contain another level of element. Let's say that the cells, i.e. <TD>, contains a <DIV>. Using //TABLE[2]/TR[3]/TD/DIV[1] focuses on the first div in the last row of the lower table.

Wednesday, June 9, 2010

Creating Time

I've started a new job and I'm working with my staff to see how things are done. One of the problems I see in many organizations is 'not enough time'. There never seems to be enough time in the day/week/month to get everything done.

This will always be true because there is always a pressure to get to market before the competition.

However, I have found ways of getting more done compared to someone else in the same time period. The trick is to look for lost moments.

Yesterday I was talking to a staff member while he set up an appliance. The process took 5 minutes of running commands and answering questions and around 15 minutes of the software getting installed. I asked him a question and he immediate paused to answer me. He was literally one key press away from the point the setup no longer required his attention. I stopped him and told him to press ENTER first.

When you look at what he was going to do:

  • Enter 99% of the interactive portion of setup (4 minutes, 59 seconds)
  • Answer my question (10 minutes)
  • Press ENTER to finish the interactive portion of setup (1 second)
  • Wait for the batch portion of setup to finish (15 minutes)
  • Total running time = 30 minutes

The way I would do it would be:

  • Emter 99% of the interactive portion of setup (4 minutes, 59 seconds)
  • Ask me to wait for a moment (3 seconds)
  • Press ENTER to finish the interactive portion ofsetup (1 second)
  • Answer my question (10 minutes)
  • Wait for the batch portion of setup to finish (5 minutes)
  • Total running time = 20 minutes, 3 seconds
I just saved 9 minutes and 57 seconds. I realized this saving from my class in Microprocessor Design. In this class we looked at what happens when the CPU reads in an opcode. Internal to the CPU there are various registers, arithmetic units (ALU), etc. If an opcode takes 12 cycles to execute, there are 12 steps inside the CPU where data is flowing from one area to another. What a designer will do is see if there are two steps I can do at the same time. If yes, I can reduce a cycle.

With microprocessors, you save a cycle here, a cycle there. It does not look like a lot but if you look at the ratio. I have 1 cycle saved for 12 cycles spent. This means 1/12 or over 8%. In real time, saving 8% means an extra 40 minutes a day. Over the course of a week I have an extra 3 hours and 20 minutes.

This is how you create extra time. I will also do things like using tools like expect to automate a process. Rather than typing in all the prompts to a Bourne shell script I will do the following:
  •  Run the script using sh -x <script-name>
  • This will output everything which is happening
  • Take the output and determine what all the prompts are
  • Use a tool like expect to script the response to the Bourne shell script
  • Use the expect script and while it is running do something else.
If something like this is only going to save me 5 minutes I might do something like check my email, stretch, etc. These are all things I will do in the day anyways. I might as well do them while I'm waiting for something else to finish.

Important to note however is that if you have 5 or 10 minutes while you are waiting for something, don't switch to a task that requires you to change what you are thinking about. Getting back into the right mindset for the thing you are waiting for could cost you 5 or 10 minutes. In that case there is no real savings.

So think about the times you are waiting for something and what can you do while you are waiting. Thing about what tools you can use to create situations you will be waiting and therefore able to do something else.

One last parting example, if you are using automation tools that take over your computer (they create mouse and keyboard activity), set up a Vmware image and run the tool inside the Vmware. While the automation is running, minimize the Vmware window and do something else on your desktop.