13

I am using selenium for test script. I am getting following error and this error randomly occur. When I run 10 times, I get this about twice. So it's not really reproducible. Does anyone know why this is happening? the element I am trying to click is definitely visible in the browser and doesn't move around so there is no need to resize or drag element. I am using chrome webdriver and I read other troubleshooting strategies(Debugging "Element is not clickable at point" error) and they don't seem relevant to my issue. I waited enough time as well.

UnknownError: unknown error: Element is not clickable at point (167, 403). Other element would receive the click: <div class="leftMasterBackground"></div>
Community
  • 1
  • 1
haeminish
  • 988
  • 5
  • 15
  • 29
  • Can you give us some information about what Element you want to click? It would also be interesting what elements surround it and what actions are performed before the click. – Tobias Kloss Apr 08 '15 at 07:30
  • Use explicit wait till element comes visible to click. – Helping Hands Apr 08 '15 at 07:55
  • Have all scripts and styles on the page finished loading when this error occurs? – FDM Apr 08 '15 at 07:56
  • The element gets loaded when the page is loaded so technically, there should be no waiting time required to check existence of the element(checking this element happened after a few tests of others) I checked the screenshot that was taken when the page was loaded, I could visually see the element loaded on the page so there is no reason why selenium could not detect the element. What I am trying to do is to click the element(button). It's very odd and annoying as it happens randomly. Does anyone know where about of the element selenium clicks? – haeminish Apr 09 '15 at 00:14

7 Answers7

7

There are a number of steps you can do in order to improve the stability while clicking on different UI elements:

  • Explicitly wait for it's presence in the DOM
  • Scroll into the element view
  • Check if clickable

Does it helped the stability?

WebDriverWait wait = new WebDriverWait(driver, 3)
JavascriptExecutor js = ((JavascriptExecutor) driver)

//presence in DOM
wait.until(ExpectedConditions.presenceOfElement(By.id("ID")));

//scrolling
WebElement element = driver.findElement(By.id("ID")));  
js.executeScript("arguments[0].scrollIntoView(true);", element);

//clickable
wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));

Further, if you will decide to override the default Actions interface with more customized one, you can use two type of clicks (for example): click() which will have all those stability steps and fastClick() which will be the default clicking without any varification.

Johnny
  • 14,397
  • 15
  • 77
  • 118
  • I only used the //scrolling block with my issue and it worked. Thanks. There's probably a more DRY solution in making this a function to call repeatedly all over your protractor tests. I'm sure there are many places where you need to scroll to a certain spot on the page in order to click. – JCC Feb 19 '16 at 20:00
  • @JCC in our solution, those native selenium libraries wrapped in additional abstraction level. So we have methods like: element.scrollToElement().click(), element.waitUntilPresence().click() and etc. – Johnny Feb 20 '16 at 20:33
  • 1
    fantastic job! The key thing is to SCROLL! – alansiqueira27 May 04 '16 at 18:51
2

I have solved by catching the exception and managing it like this:

        WebDriver driver = new ChromeDriver();
        WebElement element = driver.findElement(By.id("ID"));
        boolean clicked = false;
        do{
            try {
                element.click();
            } catch (WebDriverException e) {
                continue;
            } finally {
                clicked = true;
            }
        } while (!clicked);
billi90
  • 35
  • 6
  • Have a look at `ExpectedConditions.isClickable()` – Lee Goddard Mar 04 '16 at 15:23
  • 1
    I've already seen this functionality, but it doesn't work well with chromedriver. What happen is: the condition return `true`, but the element isn't effectively clickable. – billi90 Mar 08 '16 at 10:44
  • I had this error, which brought me to this page. Is your element covered by another (transparent) element? Is it animated? Is it possible to inject JS with `.executeScript` (or your binding's equivalent) to click the element? – Lee Goddard Mar 10 '16 at 12:53
2

I was also facing same problem with Chrome. I have solved that putting one line of code before clicking on the element:

scrollToViewElement(driver,xpath);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
2

for best solution , use java script to focus element Using ----> JavascriptExecutor jsnew=(JavascriptExecutor) driver; WebElement element=driver.findElement(By.xpath("")); jsnew.executeScript("arguments[0].scrollIntoView({block:\"center\"});", element);

In place of xpath you can use id , css selector : This scrollIntoView will bring the this specific element in middle of page , themn driver wil be able to hit element.

if it is normal button or link , use jsnew.executeScript("arguments[0].click();",element);

This is consistent solution for click.

1

click parent element of the element which you want to click. this can be workaround solution only.

Balu
  • 11
  • 6
0
  • This happens only on chrome so it works on ie and firefox
  • ChromeDriver always clicks the middle of the element
  • The reason Chrome driver doesn't calculate the correct screen location of link.

Solution:

// Find an element and define it

WebElement elementToClick = driver.findElement(By.xpath("some xpath"));
// Scroll the browser to the element's Y position
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().y+")");
// Click the element
elementToClick.click();
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

I got the same issue due to one of spinner was hiding the element.

I gave xpath and it resolved the issue. Other people suggested to 1. scroll 2. sleep also worked for them.

dimyo
  • 133
  • 1
  • 10
  • you can also solve the following error using wait condition: waitUntilTrueOrTimeout(ExpectedConditions.invisibilityOfElementLocated(elementHidingOtherElement)); protected V waitUntilTrueOrTimeout(final ExpectedCondition isTrue) { return waitUntilTrueOrTimeout(isTrue, waitTimeOutSeconds); } protected V waitUntilTrueOrTimeout(final ExpectedCondition isTrue, final int waitTimeSeconds) { return new WebDriverWait(this.driver, waitTimeSeconds).ignoring(StaleElementReferenceException.class).until(isTrue); – dimyo Aug 02 '17 at 10:42