0
votes

Firebug shows : <a class="ng-binding" ng-click="goto(menu.MenuInfo.Href)">

FirePath shows : html/body/nav/div[1]/div[1]/ul/li[3]/a

It shows as above when I use Firebug or FirePath to find the web element; Then I copy it to Selenium IDE Target text and click the find button , But it cannot find the web element. How can I find the web element and make it run in Selenium IDE to record script?

1

1 Answers

0
votes

Automatic XPath detectors are usually not a good choice when trying to figure out the Selenium locator for a specific web element. Especially expressions with numeric indexes (e.g. your li[3]) are likely to change if list/table items are removed, added or resorted.

The best way to locate an element is always by id, as this is always unique (unless you have invalid HTML). But your element doesn't have one, unfortunately.

For <a> elements, it's usually good to use the LinkText for locating the element, provided that a) it's unique and b) your site doesn't have a language toggle functionality, which usually changes all link texts.

Alternatively, you could use the tag name and class via CSS selector:

a.ng-binding

Still, it depends on the structure of your page whether this locator is unique or not. There are no general rules for finding the best locator, just good and bad strategies.