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.
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.
Selenium clicks on span instead of the button. That is why click() is not working. Please use an Id or name if available or change the xpath to include the button tag as well. If you can post the html it will be easy to create the xpath.
The exception “Element is not clickable at point” might be thrown when the element is not under focus or the action is being performed on the incorrect WebElement. In such cases, you have to switch to the actual element and perform the click action.
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.
Try the below.
driver.findElement(By.id("searchMovielanding")).sendKeys(KEYS.ENTER);
In IE, some times click does not work.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With