Thursday, September 6, 2012

Chrome browser work around for : org.openqa.selenium.NoSuchElementException: The element could not be found

Many folks trying to automate UI tests using Selenium2/Webdriver must have faced below exception:org.openqa.selenium.NoSuchElementException: The element could not be found (WARNING: The server did not provide any stacktrace information) Especially using Chrome browser. I had a test which was working perfectly on Firefox browser for many weeks and then when I started to run the same on chrome, I ran into the above exception. There is a ticket on the chrome driver project for this and many people are working around the problem using the low level class Actions. The original issue was ChromeDriver finds the co-ordinates to click in one step and sends the clicks via java Robot API in another call and there is some inconsistency in that. I tried using the Actions.perform call but my tests were still unstable(that pass sometimes and fail sometimes). So in addition to that I started running the test with Chrome in full screen mode using: capability.setCapability("chrome.switches", Arrays.asList("--start-maximized")); That helped me and I do not have those unstable tests anymore. Let me know if this helps someone.