Selenium WebDriver Click () not working with IE9

(I looked at many other similar posts on SO and, unfortunately, could not solve this problem, so here it goes ...)

I am using Selenium WebDriver (C # implementation, version 2.15) to manage a fairly simple web page. The page contains a form with two characters, input> for username and password, and one <input> for submitting the form. I can successfully enter values โ€‹โ€‹for the username and password, but calling Click () on the submit button has no effect.

In other recommendations, I tried the following tricks, none of which worked:

  • Change window focus to currentWindowHandle
  • Click on the parent item, then on the item
  • Adding a long implicit wait
  • Add a long explicit wait (sleep 20 seconds)
  • Click on a number of item elements
  • Use the Submit () function instead of Click ()
  • Send the keys "\ n" to the element (Selenium reports this as an error)

Please note that I checked that the <enter button> was indeed successfully found, so this does not seem to be a problem.

Also, please note that I have confirmed that the button does work outside of Selenium Earth. That is, I can go to the site, enter the credentials and click the submit button (and it works!).

Also note that this issue applies to IE. This does not happen for me with Chrome and FF7.

So does anyone have any other ideas?

+7
source share
10 answers

Is your site publicly available for testing? Is your IE zoom level at 100%? This is a requirement for custom 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 does not work, this seems like a bug in the webdriver. You must open the problem here .

Having said that, you could probably go the way of the Java script as a workaround. Something like,

driver.navigate().to("javascript:document.getElementById('yoursubmitbutton').click()"); 
+5
source

It looks like this could be a problem with where the mouse click occurs. I tried using the "Actions" mechanism in Selenium to click with a slight offset. It will successfully click an element:

 new Actions(GuiOps.driver).MoveToElement(e).MoveByOffset(5,5).ClickAndHold().Release().Perform(); 
+2
source

I had this problem. I cannot recall the message where I found the permission, but I found that the following worked for me:

On the button:

  var navButton = driver.FindElement(By.Id("NavButton")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", navButton); 

It works every time.

I also had problems sending the click event to the table row. Sometimes .Click () actually sends the event to the line above (we have a terribly complicated table structure that has a hidden switch in it that is also not available for Selenium). The above hack will not work with cells accessible via FindElement.

As a result, the only thing that worked was to select the image inside this line and send a click on it.

 var img = driver.FindElement(By.Id("fim{4C3DE9FA-45B0-40E0-BD95-9EE0374EA38A}")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", img); 

Hope this helps.

+1
source

I see several solutions here, but I thought I would share what worked for me if someone else out there needs a different approach. I had a similar problem, for me the solution was as simple as clicking using another method

for example

 btn.Sendkeys(Keys.Enter); 
+1
source

Use FindElement(By.CSSSelector("'CSSPath'")) ; If you have any CSS applied to the button, its more consistent alternative may be to write several other statements to find an element with alternative means, such as an identifier, tag, or so using the WebDriverWait Method

0
source

Perhaps you need to set Enable Native Events to โ€œtrueโ€ when you run it in IE, and if you want to run the same code in FF and Chrome, then you need to enable โ€œSource Eventsโ€ in true Browsers too.

This can be done by setting up the browser on which you want to run.

0
source

Try the code -

 driver.FindElement(By.Id("btn")).sendkeys("\n"); 
0
source

try it.
WebElement hiddenWebElement = d.findElement (By.xpath (xpath)); ((JavascriptExecutor) d) .executeScript ("Arguments [0] .click ()", hiddenWebElement);

0
source

The following worked for me:

 @FindBy(id = "submit_action") WebElement submitButton_; ... public void clickSubmit() { if (driver_ instanceof InternetExplorerDriver) { ((JavascriptExecutor) driver_).executeScript("arguments[0].fireEvent('onclick');", submitButton_); } else { submitButton_.click(); } } 

Since fireEvent is only supported by IE, an alternative.

0
source

Another possible workaround may resemble repeating a click:

 Btn.click(); Btn.click(); 

Because the first click just sets the focus, and the second performs a real click. It worked for me.

-one
source

All Articles