1

The element not clickable error that usually appears in chrome driver happens to be showing in firefox also. The error message shown:

  Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not clickable at point (141, 299.29998779296875). Other element would receive the click: <div class="showOnTop" id="loadingPanelContainer"></div>
Command duration or timeout: 209 milliseconds
Build info: version: '2.51.0', revision: '1af067dbcaedd7d2ab9af5151fc471d363d97193', time: '2016-02-05 11:20:57'
System info: host: 'Bhaveen-ThinkPad', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.13.0-77-generic', java.version: '1.7.0_95'
Session ID: 08e0d738-b946-4886-a179-9659d44b717b
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true,    browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true,  applicationCacheEnabled=true, takesScreenshot=true, version=44.0.2}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
    at config.KeyActions.handleLeftMenu(KeyActions.java:479)
    at scripts.Vital_Data_Script.setVitalData(Vital_Data_Script.java:383)
    at scripts.Vital_Data_Script.executeActions(Vital_Data_Script.java:95)
    at scripts.Vital_Data_Script.executeTestCase(Vital_Data_Script.java:60)
    at scripts.Vital_Data_Script.main(Vital_Data_Script.java:31)
1
  • Try using waits. Commented Feb 12, 2016 at 5:49

2 Answers 2

2

You should probably wait for the element to be clickable, You can use:

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.elementToBeClickable(By.<your locator>));

OR Sometimes you will even need to hover over the element to make it clickable. This you can do by this:

String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
            ((JavascriptExecutor) driver).executeScript(mouseOverScript,
                     driver.findElement(By.<your locator>));

After doing this you can try :

Normal click() function:

driver.findElement(By.<your locator>).click();

OR

Non-native javascript executor:

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();",  driver.findElement(By.<your locator>));
Sign up to request clarification or add additional context in comments.

4 Comments

I wish you hadn't added the OR but in, the original answer was correct.
Hi Ardesco, I understand that using this option is not a great idea. But I work on IE mostly and you already know how strange it behaves sometimes and makes it tough to make things work over there as compared to FF or Chrome. This is the last option that sometimes one has to go for.
I'll reiterate my comment I added to the answer you deleted. By using a JavascriptExecutor to click an element you are bypassing the protections that Selenium has put in place to make sure that you are not clicking on something a user cannot interact with. It will make the test pass, but it's not all about green tests. You also need to make sure that tests actually check that things work. Some things are just not suitable for automation and they need to be checked manually. It's better to have no automated test, than an automated test that gives the illusion that everything works
Ah sorry, it wasn't you who commented in the other answer, it was somebody else.
1

Prateek's answer is correct. However something I've noticed with the latest version of Firefox and Selenium 2.50.1 is that it's not always scrolling the element into view successfully.

If your problem is that the element is scrolled off the screen (and as a result under something like a header bar), you can try scrolling it back into view like this:

private void scrollToElementAndClick(WebElement element) {
    int yScrollPosition = element.getLocation().getY();
    js.executeScript("window.scroll(0, " + yScrollPosition + ");");
    element.click();
}

if you need you could also add in a static offset (if for example you have a page header that is 200px high and always displayed):

    public static final int HEADER_OFFSET = 200;

    private void scrollToElementAndClick(WebElement element) {
    int yScrollPosition = element.getLocation().getY() - HEADER-OFFSET;
    js.executeScript("window.scroll(0, " + yScrollPosition + ");");
    element.click();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.