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.
<div class="loading-container" ...>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.