开发者

xpath locator works in FF3, but won't work in IE7

开发者 https://www.devze.com 2022-12-08 03:58 出处:网络
After switching from firefox testing to internet explorer testing, some elements couldn\'t be found by selenium anymore.

After switching from firefox testing to internet explorer testing, some elements couldn't be found by selenium anymore.

i tracked down one locator:

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

While it works as it should under firefox, it could not find this element in ie. What alternatives do i have now? JS DOM? CSS Selector? How would this locator look like?

Update:

I will provide an example to make my point:

<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 followi开发者_如何学Gong xpath won't work:

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

In my understanding this should be the same as:

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

and i don't have any links that are the second child of any node. All i want is, to address one link from the set of links of class 'someClass'.


Without knowing the rest of your HTML source it's difficult to give you alternatives that are guaranteed to work. Hopefully the following suggestions will help point you in the right direction:

  • //a[@class='someClass'][2]
    This is like your example, but the parantheses 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 2nd child element of it's parent.

Update

  • Based on your update, try the following:
    //body/descendant::a[@class='someClass'][2]
0

精彩评论

暂无评论...
验证码 换一张
取 消