Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver Click() fails with IE9

Tags:

selenium

(I've looked at many other similar posts on SO and have unfortunately not been able to solve this problem, so here goes...)

I'm using Selenium WebDriver (C# implementation, version 2.15) to drive a fairly simple webpage. The page contains a form with two < input >'s for username and password, and one < input > for submitting the form. I can successfully enter values for username and password, but the Click() call on the submit button appears to have no effect.

Per other recommendations, I have tried the following tricks, none of which has worked:

  • Change window focus to currentWindowHandle
  • Click on the element's parent, then on the element
  • Add a long implicit wait
  • Add a long explicit wait (by sleeping 20 seconds)
  • Click a whole bunch of times on the element
  • Use Submit() instead of Click()
  • Send the keys "\n" to the element (Selenium reports this as an error)

Note that I have verified that the < input > button is indeed successfully found, so that doesn't seem to be a problem.

Also, note that I have verified the button does indeed work outside of Selenium-land. That is, I can browse to the site, enter login credentials, and click the submit button (and it works!).

Also, note that this problem is on IE. It does not occur for me with Chrome and FF7.

So that said, does anyone have any other ideas?

like image 903
Stephen Gross Avatar asked Jan 03 '12 21:01

Stephen Gross


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.

What is alternative for click in Selenium?

Alternative of click() in Selenium We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method. The parameters – arguments[0]. click() and locator of the element on which the click is to be performed are passed to this method.

How does Selenium verify a click?

To verify, if the element can be clicked, we shall use the elementToBeClickable condition. A timeout exception is thrown if the criteria for the element is not satisfied till the driver wait time.

Why sendKeys is not working?

sendKeys() not working in Selenium WebdriverSelenium can run JavaScript commands with the help of the executeScript method. JavaScript command to be used is passed as a parameter to this method. To input text we shall first identify the edit field with the JavaScript method document. getElementsByClassName.


1 Answers

Is your site publicly available for test? Is your IE zoom level at 100%? It is a requirement for native click events to work from the documentation here

The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

If this doesn't work then it seems a bug in webdriver. You should open an issue here.

Having said this, you could probably go the Java script route in the meanwhile as a temporary solution. Something like,

driver.navigate().to("javascript:document.getElementById('yoursubmitbutton').click()");
like image 168
nilesh Avatar answered Oct 13 '22 06:10

nilesh