0

I'm trying to automate a web application with selenium java and this is the message I keep getting org.openqa.selenium.ElementClickInterceptedException: Element is not clickable at point (85,37) because another element obscures it in all the browsers.

I tried all the waits, explicit wait for 20 seconds seems to work but often it fails too. Also, this is happening before almost every element on the application and I think applying explicit wait or Thread.sleep before every element is a good practice.

    driver.findElement(By.xpath("//span[contains(text(),'Agent Corrections')]")).click();

    WebDriverWait wait1 = new WebDriverWait(driver, 20);
    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));

    String expectedText = "";
    String actualText = driver.findElement(By.cssSelector("#users_management > div.panel-heading > h4")).getText();
    Assert.assertEquals(expectedText, actualText);

    driver.findElement(By.xpath("//span[contains(text(),'')]")).click();

    driver.findElement(By.xpath("//span[contains(text(),'')]")).click();

    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));
    driver.findElement(By.id("pcc")).sendKeys("");
    driver.findElement(By.id("pnr")).sendKeys("");
    driver.findElement(By.id("FFFormSubmit")).click();

    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));

element obscuring is with div id = preloader

kjSel
  • 3
  • 3
  • Can we get page URL? – IPolnik Sep 05 '19 at 16:22
  • You can also check for individual elements to be visible/clickable/interactable before using them. This would be in place of checking for absence of the overlay – DMart Sep 05 '19 at 17:23
  • Unfortunately i cannot give you the page URL cause it's under the organisation. However, when I use anything else instead of "invisibility of element located" in explicit wait, it fails. It could also be the issue of the web application not being stable. – kjSel Sep 05 '19 at 18:11
  • 20+ second wait for every element sounds like a serious issue. Are you uploading large files? – pcalkins Sep 05 '19 at 19:11
  • No, there are no files. Plus i talked to one of the developers and he ignored the issue by saying this problem is because his code is back end and my script is front end. Searched a lot but couldn't find a solution for this. – kjSel Sep 05 '19 at 19:21
  • Odd response, but this does seem like a front-end script problem. Can you post the script for displaying/closing the preloader div? Sounds like that's waiting for something to happen and it's hitting a timeout or something. – pcalkins Sep 10 '19 at 18:34
  • This is the preloader element and till now i found only explicit wait to resolve this, however i cannot say it's resolved cause most of the times it fails
    – kjSel Sep 11 '19 at 19:06

1 Answers1

0

I would first check if the preloader is displayed and then wait for its invisibility. This probably makes the execution bit slower, but it is fail safe.

driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS) // this will make wait time of 5 seconds for each element including preloader.

WebDriverWait wait1 = new WebDriverWait(driver, 20);
 if(driver.findElement(By.id("preloader")).isDisplayed())
{    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));
}
Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18
  • I've tried this technique before, but it's not fail safe. With timing you may never find it displayed and then this will break. – DMart Sep 05 '19 at 17:21
  • yes. it depends on the application and wait time may need to be adjusted. – Sureshmani Kalirajan Sep 05 '19 at 17:31
  • This works faster than my approach, but then again the issue is that exception comes before every element when the page loads. And Thread.sleep is not a good approach to apply before every element cause if I have a larger test script it would take ages for it to be completed. – kjSel Sep 05 '19 at 18:12
  • You shouldn't mix implicit waits with explicit waits. – DMart Sep 06 '19 at 18:59