views:

246

answers:

2

Hi All!

I'm having trouble with my xpaths in the Firefox plugin. I have three textboxes, the first one has ID=login and the rest has dynamically generated IDs. The first one works fine to write in the plugin, //input[@id='login'] but as soon as I try something more advanced, it cannot find anything. After reading plenty of forum posts, I've tried the XPather plugin to generate the xpath codes but the long html/css-filled strings don't work either. In some threads, people write "xpath=//..." and I tried that too, to no result.

Thankful for all help possible!

//M

A: 

Alright, I found some new information and it does work with writing "xpath=/" and the auto-generated codes from XPather. Although, the xpaths are very long and rely a lot on the HTML tags staying the same.

Does anyone have a better idea for xpath expressions (or css expressions) to write in order to enter information in the following three textbox elements:

TEXTBOX 1

  • Firebug: input type="text" tabindex="110" name="6011300f91d9f186d1b7ab1a034827da" id="input1"
  • Working xpath in Selenium, retrieved from XPather: xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[1]/input[@id='input1']

TEXTBOX 2

  • input type="password" tabindex="110" name="0de4766295b7a965fc4969da3df6824ba"
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[2]/input

TEXTBOX 3

  • input type="password" tabindex="110" class="last" name="6c4e0fcde65e258c3dc7c508a1cc666a"
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[3]/input

//M

Margareta
You should post the sample HTML as a reference. I suspect it's possible to use the CSS or DOM locator strategy, but I'd need to see the code.
pnewhook
A: 

The two tools I use are Firefox and XPath Checker, both Firefox add-ons.

In Firebug, select the HTML tab, right click on the element and select "Copy XPath"

For XPath Checker, right click on the element in the page and select "View XPath".

You can check this by pasting the result into the target field of Selenium IDE and then clicking the "Find" button. This tells what the Selenium result is going to be (much faster than having to run the test over and over!)

I've found that you have to "massage" the result somewhat e.g.

If you go to the Google home page and look for the "Images" link at the top left, the XPath Checker gives the image XPath as:

//id('gbar')/x:nobr/x:a1

This throws an error:

If you remove the id e.g

//x:nobr/x:a1

you'll notice that the image has a green box around it showing thet the IDE has correctly parsed it.

nzpcmad