8

I am trying to automate a website using selenium in IE 10. The site opens fine however when I want to click on a element(button) it finds the element and clicks on it as well however the elements state(button name changing) which needs to be changed doesn't change.

Here is my code.

   File file = new File("D:/IEDriverServer.exe");
   System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );

   DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
   capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
   true); 

   WebDriver driver = new InternetExplorerDriver(capabilities);
   driver.get("http://www.midomi.com");
   driver.findElement(By.id("searchMovielanding")).click();

I tried on two machines. On one machine the code ran properly and on another the dont see the click event changing the element state. I checked for the element on the webpage and found it however dont know why it is not clicking it properly on one machine.

  if(driver.findElements(By.id("searchMovielanding")).size() != 0) {
 System.out.println("Element Found");
 }

Any help to resolve this appreciated.

1
  • Would need to see the site to be able to help you. Otherwise, this is just a guessing game. See: stackoverflow.com/help/mcve Commented Jul 18, 2014 at 16:30

8 Answers 8

10

Try the below.

driver.findElement(By.id("searchMovielanding")).sendKeys(KEYS.ENTER);

In IE, some times click does not work.

Sign up to request clarification or add additional context in comments.

5 Comments

Can you explain In IE, some times click does not work?
I now had the same problem in IE. It worked for weeks but now element.click() is only selecting it and not issue a real click.
thats true, even I am struggling with the same issue, i had to use keys.enter too...
IE requires the mouse in order to get the click to work, so for headless mode or if you're not actually on the server and the mouse isn't available to the driver, the click action will fail. Another reason is if you're selecting an element that is "not displayed", you wouldn't be able to use the .click() method nor this .sendKeys(Keys.Enter) method. Other option is to do: IJavaScriptExecutor.ExecuteScript("arguments[0].click();", element); Found this to be the most reliable way of getting clicks to work in selenium across all browsers/devices.
2

This is actually a defect in the Selenium InternetExplorerDriver and they are not currently planning to address it. The link also has some suggested workarounds. However they did not work too well for me. I'll update if I can find anything. https://code.google.com/p/selenium/issues/detail?id=4403

Comments

2

The below trick worked for me. Add the code snippet where browser selection

// Setting attribute native Events to false enable click button in IE
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents",false);
WebDriver driver = new  InternetExplorerDriver(caps);

Comments

1

Adding up on previous answer. Use the following solution to click on links:

driver.findElement(By.id("searchMovielanding")).sendKeys(KEYS.ENTER);

However, ENTER key will trigger a submit on HTML forms BEFORE the click on the button. SPACE key on the other hand, clicks a button and does not submit the form (unless that is what the button is supposed to do). So suggest you rather use the following for buttons:

driver.findElement(By.id("searchMovielanding")).sendKeys(KEYS.SPACE);

Comments

1

I had the same issue with IE 11. Hope this will work for you as well.

capabilities.setCapability("nativeEvents",false);
capabilities.setCapability("ignoreZoomSetting", true);

If it's not work, try to perform click using javascript as a workaround.

Comments

1

I have faced the same issue in the past and would recommend using Actions class for clicking in IE10 or IE11

Actions act = new Actions(driver);
WebElement p=driver.findElement(By.id("element id"));
act.click(p).build().perform();

You may also use Javascript Executor for the same

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("return document.getElementById('ELEMENT ID').click();");

Comments

0

I would recommend not to use

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

as it bypasses the Protected Mode settings in IE browser. Read more here: http://jimevansmusic.blogspot.in/2012/08/youre-doing-it-wrong-protected-mode-and.html

In case you are getting any error while running without setting above capability in the code please make sure you have followed all the required configurations: https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration

Now, rerun your test and fork me what you experience.

1 Comment

IE 9 has a glitch it seams. If I restart the machine everything worked as intented. Noone knows... .
0

Using IJavaScriptExecutor solves the problem of clicking in IE many times. As it happened in my case when I was trying to click an element in the left frame of my application it was clicking undesired link but I was able to click on desired element by using below code

IWebElement element_xpathAddVar = Browser.Driver.FindElement(By.XPath("//*[@id='td_48']/a"));
js.ExecuteScript("arguments[0].click();", element_xpathAddVar);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.