1

Good day everyone,

I need your help in this method. I have a web page that will have a loading screen UI when the page loads, and I'm waiting for it to finish before clicking a button.

Here is my code:

@Step("Go to Audit Inquiry Screen")
public void launchAuditInquiry(){
    WebDriver webDriver = Driver.webDriver;
    WebDriverWait wait = new WebDriverWait(webDriver, 10);

    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));

    WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
    auditInquiryBtn.click();
}

My issue is sometimes, this code works fine. It will wait for the loading ui div to be invisible before clicking the button. But sometimes it will produce this error:

Error Message: org.openqa.selenium.WebDriverException: unknown error: Element <a class="module-item" href="/audit/inquiry">...</a> is not clickable at point (822, 436). Other element would receive the click: <div class="loading-container" style="display: flex; opacity: 0.899842;">...</div>

I tried adding another explicit wait before clicking the button to be sure, like this:

    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));

    WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Audit Inquiry")));
    auditInquiryBtn.click();

But it will sometime produce the same error above, and sometimes it will work fine.

I'm just confused on how to remediate the issue.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
cas
  • 39
  • 6
  • 2
    Possible duplicate of [Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click:](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el) – undetected Selenium Jan 17 '18 at 10:35
  • The problem is not that the element is not there. The problem is that another element, `
    ` is on top of that element so that Selenium won't click it. The fix here is to wait for that loading container to be visible and then invisible before attempting to click your desired element. If I were to guess, there's some loading... popup that comes up while the page or part of the page is loading.
    – JeffC Jan 17 '18 at 14:12

2 Answers2

1

Thank you guys for the comments, especially this: Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click

It was helpful, but some items there, I have already tried, but did not work as well. The part that I did check was one item there and also a comment here also which is to force a click:

new Actions(driver).moveToElement(auditInquiryBtn).click().perform();

But I'm having second thoughts on this because, a scenario may happen that when the loading container div is still overlaying the page, then I forced clicked the submit button, it will also produce another loading container div, and I'm not sure what will happen if there are two loading container div present.

Now, my solution on this is to adjust the sleep timer of the wait function:

WebDriverWait wait = new WebDriverWait(webDriver, 10, 2500L);

It now works because it gives the loader div time to generate before the first check of wait. 500 ms was a bit fast for the loader to render. I'm still testing this but if it didn't work, I might do the solution above.

Thanks again.

cas
  • 39
  • 6
0

First thing to try is remove the invisibilityOfElementLocated wait and just use elementToBeClickable. I've never really trusted what Selenium considered "visible" and "invisible".

I've had issues in the past where the element to click on was completely off screen, so Selenium automatically scrolled until it was considered in the viewport. But because of a floating footer, it didn't scroll enough and was still behind the footer so could not be clicked on. It was still considered "visible" because it was in the viewport.

But, if you're sure, you can try forcing a click at a coordinate instead of an element.

new Actions(driver).moveToElement(auditInquiryBtn).click().perform();
MivaScott
  • 1,763
  • 1
  • 12
  • 30