Selenium, Firebug and Xpath (updated)

Posted: February 2nd, 2011 | Author: | Filed under: general | 2 Comments »

Today I was working on writing a selenium test to ensure a feature was working properly on our site.  The button I was trying to click had a duplicate button on the page and each did something different.  The problem was that they were both in different forms, but had the same name and no ID.  In  selenium the only way to target the specific button is via XPath.  The XPath for this is a little crazy:

//div/div[2]/div/div/div[2]/div/div/div[2]/div[2]/div[2]/div[2]/div/form/input[13]

Now I spent a bit of time trying to figure it out manually and quickly gave up.  I figured firebug might have something and sure enough if you “Inspect Element” on the button firebug pops up with the full html path to the element shown across the top of the firebug window.  Hovering over each element gives you the full XPath and right clicking lets you do a few different operations such as Copy Html and Copy XPath.  Now the XPath that it gives you will look like

/html/body/div/div[2]/div/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div/form/input[13]

I removed the /html/body and replaced with // to match the rest of the XPath that selenium generates, replaced the name=fieldname in my test and it worked.

*Please NOTE*

This is horrible don’t ever use it 🙂 – All joking aside if you have the option to add a class or an id(as rasenplanscher points out in the comments below) to an element on the page that you need to target you should do that instead.  If you can’t like this situation, this will work for you.


Un-Bustable: Why Mythbusters should stop doing some myths

Posted: October 13th, 2010 | Author: | Filed under: general | Tags: , , | Comments Off on Un-Bustable: Why Mythbusters should stop doing some myths

I love the Mythbusters, my 6 year old son loves the Mythbusters, in fact we now have a Friday night ritual where we camp out in the family room and watch the show. That being said I feel that there are a few myths that have been tackeld by the show that should not be.  Not because they are not interesting to watch but because they are “un-bustable”.  Lets take for example the breathalyzer, they tried about 5 or 6 methods to try and beat the test, none of them worked; shocking!  Lets say that they had found an easily reproducible method for defeating the machine, am I expected to believe that the hosts Adam and Jamie, the producers of the show, The Discovery Channel, the District Attorney, etc would have ever let such an episode air? If they had found that gargling milk mixed with hot sauce, rasins and fish sauce let you pass the breath test we would never have seen the segment. The same can be said for one of the most recent episodes, beating the drug sniffing dog. Again had they found a sure fire way to do so, it would not be at all responsible for them to air the episode. Beating the radar gun, ditto.

The show is great let me make that clear, but they should just stop trying to bust the un-bustable myths.  I’d love to read your comments on this, has this bothered you as well?