Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - Element is not clickable at point

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>
like image 729
haeminish Avatar asked Apr 08 '15 07:04

haeminish


2 Answers

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.

like image 77
Siddiqui Arshad Avatar answered Oct 23 '22 05:10

Siddiqui Arshad


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.

like image 35
Johnny Avatar answered Oct 23 '22 06:10

Johnny