Selenium.click not working on some anchor elements

A.J picture A.J · May 26, 2011 · Viewed 12.2k times · Source

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

Answer

artbristol picture artbristol · May 26, 2011

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