Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium.click not working on some anchor elements

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

like image 301
A.J Avatar asked May 26 '11 06:05

A.J


People also ask

Why click is not working in Selenium?

We can list the most common reasons for click problems as being one of the following: Wrong web element locations. The existence of a web element that obscures the web element that we want to click. The Selenium WebDriver works much faster than the response of the application.

How do I find the xpath of an anchor?

Just right click on the element of the webpage and select inspect element. If the XPath is correct, then the desired element will be highlighted, and you can use this as a locator in your automation test. and so on. And some of the common attributes are class, id, name, href, title, etc.

Can we use HREF in Selenium?

We can get an attribute value from a href link in Selenium. To begin with, we have to first identify the element having an anchor tag with the help of any of the locators like css, id, class, and so on. Next, we shall use the getAttribute method and pass href as a parameter to the method.

How do I get Selenium to click?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it. A button in html code is represented by button tagname.


1 Answers

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')");
like image 165
artbristol Avatar answered Oct 10 '22 05:10

artbristol