Skip to content

Commit 1e5fb3e

Browse files
committed
Wait for DOM to fully load - a potential fix for StaleElementReferenceException when running testCrawlEhrLinks()
1 parent 3f50b39 commit 1e5fb3e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.labkey.remoteapi.SimplePostCommand;
2222
import org.labkey.test.Locator;
2323
import org.labkey.test.Locators;
24+
import org.labkey.test.WebDriverWrapper;
2425
import org.labkey.test.pages.ehr.AnimalHistoryPage;
2526
import org.labkey.test.util.Crawler;
2627
import org.labkey.test.util.DataRegionTable;
@@ -32,6 +33,7 @@
3233
import org.labkey.test.util.external.labModules.LabModuleHelper;
3334
import org.labkey.test.util.selenium.WebDriverUtils;
3435
import org.openqa.selenium.By;
36+
import org.openqa.selenium.JavascriptExecutor;
3537
import org.openqa.selenium.Keys;
3638
import org.openqa.selenium.WebDriverException;
3739
import org.openqa.selenium.WebElement;
@@ -436,6 +438,13 @@ private void validatePageLinks(Set<String> crawledLinks)
436438
{
437439
log("Validating links on " + getURL());
438440

441+
// Wait for DOM to be fully loaded and stable
442+
WebDriverWrapper.waitFor(() -> {
443+
String readyState = (String) ((JavascriptExecutor) getDriver())
444+
.executeScript("return document.readyState");
445+
return "complete".equals(readyState);
446+
}, 5000);
447+
439448
// Find all anchors in the body content area, excluding buttons and those in data regions
440449
List<WebElement> 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'))]"));
441450

0 commit comments

Comments
 (0)