Wanderer
Wanderer

Reputation: 476

Element click not functioning properly using selenium in IE 10

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.

Upvotes: 8

Views: 25099

Answers (8)

Ritica Ramakrishnan
Ritica Ramakrishnan

Reputation: 79

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();");

Upvotes: 1

Sachitha Dilshan
Sachitha Dilshan

Reputation: 343

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.

Upvotes: 1

Juan C Calderon
Juan C Calderon

Reputation: 81

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);

Upvotes: 1

user7609638
user7609638

Reputation: 1

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);

Upvotes: 0

Jag
Jag

Reputation: 21

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);

Upvotes: 2

KyleK
KyleK

Reputation: 646

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

Upvotes: 2

Sitam Jana
Sitam Jana

Reputation: 3129

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.

Upvotes: 0

Purus
Purus

Reputation: 5819

Try the below.

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

In IE, some times click does not work.

Upvotes: 10

Related Questions