开发者

Selenium IDE - JQuery onclick handler not triggered

开发者 https://www.devze.com 2023-02-24 22:50 出处:网络
I am trying to test a page using the FF Selenium IDE plugin. There is a menu structure like the following..

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 开发者_如何学Cusing 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.


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")

0

精彩评论

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