Xpath locator works in FF3 but doesn't work in IE7

After moving from testing firefox to testing in Internet Explorer, some items can no longer be found by selenium.

i tracked one locator:

xpath=(//a[@class='someclass'])[2]

      

While it works as it should in firefox, it cannot find this element in ie. What alternatives do I have now? JS DOM? CSS selector? What does this locator look like?

Update:

I'll give an example to point out:

<ul>
  <li>
    <a class='someClass' href="http://www.google.com">BARF</a>
  </li>
  <li>
    <a class='someClass' href="http://www.google.de">BARF2</a>
  </li>
</ul>
<div>
  <a class='someClass' href="http://www.google.ch">BARF3</a>
</div>

      

The following xpath won't work:

//a[@class='someclass'][2]

      

In my understanding, it should be the same as:

//a[@class='someclass' and position()=2]

      

and I have no links that are the second child of any node. All I want is to access one link from the set of links of the "someClass" class.

+2


source to share


1 answer


Without knowing the rest of your HTML source, it is difficult to provide you with alternatives that are guaranteed to work. We hope that the following guidelines will guide you in the right direction:

  • //a[@class='someClass'][2]


    This is similar to your example, but the parentheses are not needed.

  • //a[contains(@class, 'someClass')][2]


    This will work even if the link has other classes.

  • css=a.someClass:nth-child(2)


    This will only work if the link is the second child of the parent.



Update

  • Try the following based on your update:
    //body/descendant::a[@class='someClass'][2]

+3


source







All Articles