Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 452
Wanderer Avatar asked Jul 17 '14 23:07

Wanderer


People also ask

Why click function 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 you do when click function not working in Selenium script?

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.

Why are elements not clickable?

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.

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.


Video Answer


2 Answers

Try the below.

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

In IE, some times click does not work.

like image 195
Purus Avatar answered Oct 01 '22 02:10

Purus


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

like image 39
KyleK Avatar answered Oct 01 '22 00:10

KyleK