6

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

artbristol
  • 32,010
  • 5
  • 70
  • 103
A.J
  • 4,929
  • 2
  • 27
  • 36

6 Answers6

2

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')");
Community
  • 1
  • 1
artbristol
  • 32,010
  • 5
  • 70
  • 103
  • 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 May 26 '11 at 09:54
  • 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 – A.J Jun 04 '11 at 14:18
  • 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 Jun 05 '11 at 22:48
  • might be worth trying my updated answer (my previous comment had a typo, mouseOver instead of mouseover)... – artbristol Jun 06 '11 at 15:24
  • Thanks artbristol :), I will try it. – A.J Jun 06 '11 at 16:24
  • 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 ! – atroutt Jan 29 '13 at 21:39
  • I got it working like this: runScript("jQuery(\"div.fc-event-time:contains('" + EVENT_NAME + "')\").trigger('mouseover').trigger('click');"); – Mika Vatanen Apr 02 '13 at 09:23
0

I've come across with the similar problem recently. Please note, I work with Selenium driver. So I'm not sure whether my approach is suitable for Selenium 1.xx

The problem was in clicking invisible menu elemnt , which appears on mouse hover event. The solution I found for Firefox selenium driver:

WebElement mnuElement;
WebElement submnuElement;
mnEle = driver.findElement(By.Id("mnEle")).Click();
sbEle = driver.findElement(By.Id("sbEle")).Click();

Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.MoveToElement(mnEle).Perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
driver.findElement(By.Id("sbEle")).Click();

Here's the link

Main idea is to create instance of Actions and try to focus on your element and click it. I would act in the following way: //find xpath of your invisible element:

    String xpathInvisible = "//*[id="calendar"]/div/div/div/div[1]";

//find xpath of the element, on hovering which your invisible (inactive) element appear. I mean somthing //like VDIs (see my screen) on pressing which menu elements appear.

    String xpathCalendarToAppear =".....";

WebElement calendarToAppear= driver.findElement(By.xpath(xpathCalendarToAppear));
WebElement invisibleElement=driver.findElement(By.xpath(xpathInvisible));

Actions builder = new Actions(driver);
builder.MoveToElement(calendarToAppear).Perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
invisibleElement.Click();

In firefox this works OK. But IE driver has problems with clicking on elements. So I overcome this "IE problem" using jscript directly in the following way:

WebElement hiddenWebElement =driver.findElement(By.xpath(....));
        ((JavascriptExecutor)driver).executeScript("arguments[0].click()",hiddenWebElement);

we initialize hiddenWebElement variable with element we want to click on. And using jscript we click on it.

Hope this helps you.

eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44
0

I ran into a similar problem to yours (one anchor/link element out a hundred or so I'd tested before just fine refused to be clicked by a standard selenium click method).

In my case, I was able to solve the problem, for reasons entirely unclear to me, using Selenium WebDriver Actions (documented here for Java and here for Ruby) to execute a clickAndHold/click_and_hold action followed by a release action. In Ruby, this is done like so (code example from Ruby documentation of release):

el = driver.find_element(:id, "some_id")
driver.action.click_and_hold(el).release.perform

Hoping this helps someone else, and perhaps that someone with more insight can explain the reasons behind this.

Anomaly
  • 932
  • 1
  • 10
  • 18
0

Our JQuery calendar implementation is compatible with the default Selenium locators, even though the locators appear disabled in the DOM. Here's an example, for you to try:

selenium.click("link=11:00 AM - 01:00 PM");
rs79
  • 2,311
  • 2
  • 33
  • 39
0

Ok, I just assume your XPATH to get that span is correct, I suspect your selenium script is running faster than your page load, so add this function to wait until the page is loaded

waitForPageToLoad

Hope helps :)

kororo
  • 1,972
  • 15
  • 26
  • Would have been really easy if that was the case :). It doesn't cause a page load – A.J Jun 03 '11 at 14:38
  • And to make sure wait was not the issue, I did debug the code using breakpoints. No luck :( – A.J Jun 03 '11 at 15:22
0

Do the following:

selenium.focus("locator path of where you want to click");
selenium.keyPressNative("10"); // this is clicking entering button

this should do the job.

Make sure that you don't touch the mouse while Selenium is executing your keyPressNative statement.

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
sudarsan
  • 283
  • 1
  • 4
  • Shouldn't the same work manually? Like if i hover the mouse or use tab to reach the element and then press enter? – A.J Jun 15 '11 at 16:11