javascript - Selenium IDE - JQuery onclick handler not triggered - Stack Overflow

I am trying to test a page using the FF Selenium IDE plugin.There is a menu structure like the follow

I am trying to test a page using the FF Selenium IDE plugin.

There is a menu structure like the following..

<ul class="parent">
   <li class="child"><span><a href="something.html">link text</a></span></li>
   <li class="child"><span><a href="somethingelse.html">other text</a></span></li>
<ul>

The li elements have a hover event bound to them. Those hover events register a click event on the actual link tag. (I have stripped out some of the JavaScript for simplification)

  var menu = $('ul.parent');

  $("> li.child", menu).hover(function () {

    $(this).find('> a').click(function () {             
      $(this).parent().addClass('active-trail');
      return false;
    });
  }, function() {});

If using Selenium I click one of these links then I would expect the handler to be called. It isn't and the click is simply executed (and the link followed, instead of false being returned).

I have tried (after reading other answers) mouseUp and mouseDown. I have also tried using fireEvent to firstly hover over the li (to activate the hover event) and then another fireEvent to click the anchor.. but that didn't work either.

So any help would be most appreciated. Just a basic demonstration of using Selenium to trigger a jquery supplied click handler would probably be enough to see me right!

Thanks, Patrick.

I am trying to test a page using the FF Selenium IDE plugin.

There is a menu structure like the following..

<ul class="parent">
   <li class="child"><span><a href="something.html">link text</a></span></li>
   <li class="child"><span><a href="somethingelse.html">other text</a></span></li>
<ul>

The li elements have a hover event bound to them. Those hover events register a click event on the actual link tag. (I have stripped out some of the JavaScript for simplification)

  var menu = $('ul.parent');

  $("> li.child", menu).hover(function () {

    $(this).find('> a').click(function () {             
      $(this).parent().addClass('active-trail');
      return false;
    });
  }, function() {});

If using Selenium I click one of these links then I would expect the handler to be called. It isn't and the click is simply executed (and the link followed, instead of false being returned).

I have tried (after reading other answers) mouseUp and mouseDown. I have also tried using fireEvent to firstly hover over the li (to activate the hover event) and then another fireEvent to click the anchor.. but that didn't work either.

So any help would be most appreciated. Just a basic demonstration of using Selenium to trigger a jquery supplied click handler would probably be enough to see me right!

Thanks, Patrick.

Share Improve this question asked Apr 14, 2011 at 5:20 patrickdaveypatrickdavey 2,0762 gold badges20 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You are right with fireEvent(), are you sure you were using it right?

If you want to fire the onClick handler you would do fireEvent(locator, "click") not fireEvent(locator, "onClick").

You probably are doing this right if you are using selenium IDE to generate the scripts.

Selenium is a bit dodgey in this area, I have had many similar problems.

Have you tried using xpath i.e.

selenium.Click("xpath=/descendant::li[contains(.,"something")][2]/x:a")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745256146a4618969.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信