diff --git a/ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java b/ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java index 8304d9004..c34acf7fa 100644 --- a/ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java +++ b/ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java @@ -21,6 +21,7 @@ import org.labkey.remoteapi.SimplePostCommand; import org.labkey.test.Locator; import org.labkey.test.Locators; +import org.labkey.test.WebDriverWrapper; import org.labkey.test.pages.ehr.AnimalHistoryPage; import org.labkey.test.util.Crawler; import org.labkey.test.util.DataRegionTable; @@ -32,6 +33,7 @@ import org.labkey.test.util.external.labModules.LabModuleHelper; import org.labkey.test.util.selenium.WebDriverUtils; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; @@ -436,6 +438,13 @@ private void validatePageLinks(Set crawledLinks) { log("Validating links on " + getURL()); + // Wait for DOM to be fully loaded and stable + WebDriverWrapper.waitFor(() -> { + String readyState = (String) ((JavascriptExecutor) getDriver()) + .executeScript("return document.readyState"); + return "complete".equals(readyState); + }, 5000); + // Find all anchors in the body content area, excluding buttons and those in data regions List anchors = getDriver().findElements(By.xpath("//div[contains(concat(' ', normalize-space(@class), ' '), ' lk-body-ct ')]//a[not(ancestor::form[@data-region-form]) and not(@role='button') and not(contains(@class, 'labkey-button'))]"));