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.

2 comments:

  1. I've tried doing
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));

    as well as
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    return new ChromeDriver(options);

    Still chrome is not able to click the element & is throwing

    org.openqa.selenium.NoSuchElementException: The element could not be found (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 60.01 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'
    System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.0.0-12-generic', java.version: '1.7.0'
    Driver info: driver.version: EventFiringWebDriver
    Session ID: 99f5771455259fe047a8ba926c532adf
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    ReplyDelete
  2. Didn't notice this comment till now.

    Sorry that didn't work for you. It is really just a hack and the really issue is in ChromeDriver.
    If you point me to the URL , I will give a try.
    Let me know

    ReplyDelete