Selenium WebDriver Error for IE

I am trying to automate test cases using selenium webdriver, junit and ant build. In the morning I get strange errors. The test example contains a button click command. The test succeeds in Chrome and FF, but not in IE. At least he used to say that he could not find element X, but this means that the server did not provide any information.

Testcase: testMethod took 10.342 sec Caused an ERROR Cannot click on element (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 172 milliseconds Build info: version: '2.23.1', revision: '17143', time: '2012-06-08 18:59:04' System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_33' Driver info: driver.version: RemoteWebDriver Session ID: 8dfc5072-2755-40a7-bb32-05708c51101f com.thoughtworks.selenium.SeleniumException: Cannot click on element (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 172 milliseconds Build info: version: '2.23.1', revision: '17143', time: '2012-06-08 18:59:04' System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_33' Driver info: driver.version: RemoteWebDriver Session ID: 8dfc5072-2755-40a7-bb32-05708c51101f at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:41) at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:38) at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:144) at org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:74) at com.thoughtworks.selenium.DefaultSelenium.click(DefaultSelenium.java:193) at dmswebui.IE.TestLogin.testMethod(TestLogin.java:19) Caused by: org.openqa.selenium.ElementNotVisibleException: Cannot click on element (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 172 milliseconds Build info: version: '2.23.1', revision: '17143', time: '2012-06-08 18:59:04' System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_33' Driver info: driver.version: RemoteWebDriver Session ID: 8dfc5072-2755-40a7-bb32-05708c51101f at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:458) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:77) at org.openqa.selenium.internal.seleniumemulation.Click.handleSeleneseCommand(Click.java:36) at org.openqa.selenium.internal.seleniumemulation.Click.handleSeleneseCommand(Click.java:1) at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:32) 
+4
source share
4 answers

Insert the next block before you click the click event

 for (int second = 0;; second++) { if (second >= 60) return "Page load failed"; try { if (session().isTextPresent("Logoff")) break; } catch (Exception e) {} Thread.sleep(1000); } 

In my case, I have a superclass for a test case, so I can do

 session().somecommand 

But you can translate my decision into yours.

+1
source

In the exception, I notice the following:

 Caused by: org.openqa.selenium.ElementNotVisibleException: Cannot click on element 

This usually happens when the element you click is hidden or hidden on the page. WebDriver uses its own events, so it fails when you ask it to perform an action on a hidden WebElement.

This was not a problem in Selenium RC, since it deployed synthetic events (JS events) and could simulate a click on any DOM element regardless of its visibility.

+4
source

In Internet Explorer, at least in the latest version 10 and previous 9, the DOM cannot fully reboot or be visible by WebDriver in single-page applications or heavy ajax pages where the DOM is dynamically created. I found a workaround at the moment - just refresh the page

driver.navigate().refresh();

I understand that this may seem like a hacker, but it causes the IE browser to reload the page and draw the current expected DOM elements. Even inserting WebDriverWait did not help (although this is best practice and should be implemented in most cases when working with heavy ajax applications).

During my experience, I used the latest version of webdriver (2.31.0) in a Java project and IE 10 (in mode and in compatibility mode).

As soon as I find out why IE does this, I will update this answer to a longer portable solution, and then just refresh the page. At the moment, I switched to using the Chrome driver and implemented Chrome Frame in IE.

+2
source

in my case, the problem was that the sending process took too much time, for example, more than two minutes, and my problem was solved by completing the click operation on an attempt to catch and adding sleep mode to complete the process, and then continue. Code as follows

 try { button.click(); } catch (Exception e) { Thread.sleep(1000); } 
0
source

All Articles