Selenium.click not working on some anchor elements

12,688

Try selenium.fireEvent(locater, 'click'), or using Selenium 2 which is more tightly integrated with the browser.

You may be having the same problem as some other people, eg.

Selenium clicks not working with GWT

Using Selenium to 'click' on non-input or non-control elements

It seems to be related to click events which are added with Javascript.

Edited

I don't know if you're using the same calendar implementation, but I discovered that the fullcalendar.js jQuery one replaces the mouseover event, and you have to trigger that first. I got it to work using

selenium.runScript("jQuery(\"a:contains('" + NEW_EVENT_NAME
        + "')\").trigger('mouseover');jQuery(\"a:contains('"
        + NEW_EVENT_NAME + "')\").trigger('click')");
Share:
12,688
A.J
Author by

A.J

By profession I am a Test Automation Engineer. Loves to work in Selenium and support it. Has got knowledge in JAVA, TestNG and Hudson build tool as part of my current job.

Updated on June 19, 2022

Comments

  • A.J
    A.J almost 2 years

    The application that am working on was recently revamped and as part of that a new JQuery calendar was introduced. I need to click on a link in the calendar to select the time and date. However, Selenium.click is not working. The command gets executed, but nothing happens on the screen.

    To check whether my XPATH/CSS locator (I tried both) is correct, I added selenium.getText(locator) and selenium.highlight(locator) commands. Both worked!. No issues in that. Its ONLY the click that is not working.

    Upon checking in firebug, I could see that the div on which I am trying to click is kind of grayed out state. Does it meant that element is disabled? See the screenshot of the firebug below.

    I also tried to run the same command in Selenium IDE. In IDE this works "sometimes".

    I am running this test using Selenium 1.xx.

    UPDATE:

    I did one more thing as part of debugging. During the test run, I opened the Selenium IDE in the browser so that it records what actions are happening. IDE recorded all actions till this click. But I couldn't see anything in the IDE when the click command was executed. Any idea guys, what would be cause?

    Has anyone faced a similar issue before? Any help would be appreciated!!!Firebug screenshot

  • A.J
    A.J almost 13 years
    selenium.fireEvent did not work. Unfortunately I can't move to Selenium 2 now. The other issues which you have given solved the issue using Selenium 2.
  • A.J
    A.J almost 13 years
    Would have been really easy if that was the case :). It doesn't cause a page load
  • A.J
    A.J almost 13 years
    And to make sure wait was not the issue, I did debug the code using breakpoints. No luck :(
  • A.J
    A.J almost 13 years
    Awarding the bounty to this as this is the closest answer I could get. Hopefully this issue will be resolved by Selenium 2.0. Now that Grid 2.0 is out, I can try this. Thankyou
  • artbristol
    artbristol almost 13 years
    Sorry you couldn't resolve the issue completely, if it's any consolation there are some click events which I've never managed to fire either :-(
  • artbristol
    artbristol almost 13 years
    might be worth trying my updated answer (my previous comment had a typo, mouseOver instead of mouseover)...
  • A.J
    A.J almost 13 years
    Thanks artbristol :), I will try it.
  • A.J
    A.J almost 13 years
    Shouldn't the same work manually? Like if i hover the mouse or use tab to reach the element and then press enter?
  • atroutt
    atroutt over 11 years
    mouse over and then click! That worked for me. I ran in to this with trying to click spans in an ember-based app that apparently was doing something similar. Thanks @artbristol !
  • Mika Vatanen
    Mika Vatanen about 11 years
    I got it working like this: runScript("jQuery(\"div.fc-event-time:contains('" + EVENT_NAME + "')\").trigger('mouseover').trigger('click');");