8

In regards to the Webdriver error

Element is not clickable at point (X, Y). Another element would recieve the click instead.

For ChromeDriver, this is addressed at Debugging "Element is not clickable at point" error, however the issue can occur in Firefox as well.

What are the best ways to resolve this when it occurs in FirefoxDriver?

Community
  • 1
  • 1
emery
  • 8,603
  • 10
  • 44
  • 51

8 Answers8

5

This happens in the below cases-

  • When the element is loaded into the DOM, but the position is not fixed on the UI. There can be some other div or images that are not loaded completely.

  • The page is getting refreshed before it is clicking the element.

Workaround

  • Use Thread.sleep before actions on each web element in UI, but it is not a good idea.
  • Use WebDriverWait ExpectedConditions.

I was facing the same issue, the page load time was more and a loading icon was overlapping on entire web page.

To fix it, I have implemented WebDriverWait ExpectedConditions, which waits for the loading icon to disappear before performing click action on an element

Call this function before performing an action (I am using data driven framework)

public void waitForLoader () throws Exception  {
  try {
   String ObjectArray[]=ObjectReader.getObjectArray("LoadingIcon"); 
    if(checkElementDisplayed(ObjectArray[3],ObjectArray[2]))
    {
     WebDriverWait wait = new WebDriverWait(remotewebdriver,10); 
     wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(ObjectArray[3])));
    }
   } catch (NoSuchElementException e) {
   System.out.println("The page is loaded successfully");
   }
  }
Joe
  • 51
  • 1
3

My same problem is solved by Javascript, Please try following code instead of selenium click

WebElement rateElement = driver.findElement(By.xpath(xpathContenRatingTab));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", rateElement);
David Clarke
  • 12,888
  • 9
  • 86
  • 116
Sumit2500
  • 183
  • 7
  • This worked for me when I have tried most of the other suggestions unsuccessfully. SendKeys worked for Chrome but not Firefox. Thank you. – David Clarke May 19 '17 at 00:18
3

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(); 
}

You can direct click using JavascriptExecutor (Not recommanded)

WebElement element= driver.findElement(By."Your Locator"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • This type of response is useful, however Selenium should do this automatically, so I think the better solution is to match the Firefox and Selenium versions appropriately. – emery Apr 24 '16 at 23:45
  • @ShubhramJain What is arguments[0].click() here because I am getting this error for above code org.openqa.selenium.WebDriverException: arguments[0].click is not a function – Avinash Jadhav Apr 25 '16 at 06:33
  • 1
    Why is it not recommended to use `javascriptExcutor`? – jmreicha Nov 18 '16 at 01:02
  • Seems that javascriptExcutor does not wait until new page is loaded when clicking a link – wutzebaer Dec 03 '18 at 15:03
  • yes it will not wait. you need to add ExpectedConditions before trigger it – Shubham Jain Dec 03 '18 at 15:09
2

Careful matching of the Selenium jar version with the Firefox version can fix the issue. Selenium should automatically scroll an element into view if it isn't on the page. Forcing an element into view with JavaScript is unnecessary.

We never see this issue in Firefox 31.5.0 with selenium-server-standalone-2.44.0.jar, however when upgrading to Firefox 38.7.0 with selenium-server-standalone-2.52.0.jar, it became an issue.

See https://github.com/seleniumhq/selenium/issues/1543

emery
  • 8,603
  • 10
  • 44
  • 51
  • 1
    Thank you sir!! Updating chromedriver and matching the standalone server with selenium version in gradle worked :) – MatMat Nov 01 '17 at 12:09
2

I had the same problem and I solved it using certain capability. While you are using FirefoxDriver, you can set "overlappingCheckDisabled" to true to solve your problem.

capabilities.setCapability("overlappingCheckDisabled", true);
Lorenzo Fidalgo
  • 203
  • 2
  • 8
1

ActionBuilder can resolve the error. Sometimes there is another element in front of the object that needs to be clicked, so an ActionBuilder click to the location of the element may work in cases where a traditional click fails

    Actions actions = new Actions(driver);
    actions.moveToElement(clickElement).click().perform();

or try the middle of the element

    Actions actions = new Actions(driver);
    Integer iBottom = clickElement.getSize().height;
    Integer iRight = clickElement.getSize().width;
    actions.moveToElement(clickElement, iRight/2, iBottom/2).click().perform();
emery
  • 8,603
  • 10
  • 44
  • 51
Chuck Brown
  • 353
  • 1
  • 5
  • 2
    this is very misleading. it is up to the manufacturer of the driver to determine what the click actually does, and where and how it clicks. do you have sources to show that it clicks the "top left" by default? if so, which browsers – ddavison Apr 20 '16 at 03:33
  • 1
    True each driver could be different. My assumption comes from the casting of a webElement to a Locatable gives the top left corner location. – Chuck Brown Apr 20 '16 at 15:30
  • @sircapsalot I wouldn't fully agree that it is "very misleading", since ActionBuilder is a valid solution to the error in many cases... but you make a valid point about the driver manufacturer possibly not always defaulting to the top left corner. I edited the post accordingly. – emery Nov 03 '17 at 20:29
1

This Error coud ocur when for example u make to many accesses to some service , for example if u are making as I a bot .... For example instagram will block u for some period if u ar taged as blocked and then that error coud ocour not allowing u to click some elements in the page.

Try make another acount and switch to a vpn becouse probably your ip is already marked as blocked

dan_udnas
  • 19
  • 7
0

Try to maximize the browser when you are working with resolutions greater than 1024x768. It works for me in js.

 driver.manage().window().maximize();
D.JCode
  • 386
  • 2
  • 12