If you want to use XPath to locate elements with the Selenium IDE you have basically three options to figure out the XPath definition you have to use for your test.

  1. Use the built in record function of the Selenium IDE with XPath Locator Builders.
  2. Use a plugin to figure out the XPath of a specific element and use the result in the Selenium IDE.
  3. Analyse the HTML-structure and figure out the XPath yourself.

I will provide examples for the first two options since the third option is not really practical to work with.

 

Use the built in record function of the Selenium IDE with XPath Locator Builders

  1. Open Firefox and the Selenium IDE.
  2. Go to “Options”>”Options…” and switch to the tab “Locator Builders”.
  3. Here move via drag and drop the two entries “xpath:attributes” and “xpath:idRelative” to the top of the list as you see in the screenshot.
    Selenium IDE Locator Builders
  4. Click “OK”.
  5. Now click on the red record button on the right side of the Selenium IDE to start recording.Click To Record
  6. Switch to the main Firefox browser window and navigate to https://en.wikipedia.org
  7. Type into the search field: “Selenium” and hit enter or click on the search button.
  8. Now switch back again to the Selenium IDE window and click the red button to stop recording.
  9. Your recorded test should look something like you see the sample in the screenshot. As you can see the recorder used to locate the search box and the search button relative XPaths.Recorded XPath Results
  10. If you hit the button to play the current test cases, the test should pass by using all the XPaths to locate the elements.Test Passed Sample 1

 

Use a plugin to figure out the XPath of a specific element and use the result in the Selenium IDE

  1. First you need to install some kind of XPath plugin in the browser of your choice that can help you to find out XPaths of elements on any site you are currently surfing on. For this example we are using the XPath Helper with Google Chrome.
  2. After you installed XPath Helper in Chrome you should see the Icon with your other active plugins.
  3. In Chrome navigate to https://en.wikipedia.org
  4. Click on the icon of XPath helper to launch it.Start XPath Helper
  5. Hold the shift button while you hover with the mouse pointer over the search input field.
  6. Now you should see the full XPath of the search input field in the black box of the XPath helper.
  7. Starting at the end of the XPath select as much of it as you think is necessary to have a unique XPath to the desired element. It is important that your selected fraction of the XPath always starts with a slash (“/”). Since the site probably only has one “searchInput” we only select the small portion:”/input