Currently, I am in the process of testing a website that I have developed as part of a Spring Boot project using Selenium. While I can successfully test basic functionalities such as page loading and title verification, I am encountering difficulties when it comes to examining the actual content of the page.
The specific section on my page is structured as follows:
<div id="main">
<div id="div_1"></div>
<div id="div_2"></div>
<div id="div_3"></div>
<div id="div_4"></div>
</div>
Furthermore, the content is loaded through a JavaScript script:
document.addEventListener("DOMContentLoaded", function(event) {
populateDivs()
})
To configure the WebDriver, I have incorporated certain options derived from similar inquiries (other Selenium tests are running smoothly, suggesting no conflict with the options):
final ChromeOptions options = new ChromeOptions();
options.addArguments(
"--headless",
"--nogpu",
"--disable-gpu",
"--enable-javascript",
"--no-sandbox",
"--disable-extensions",
"--disable-blink-features=AutomationControlled",
"--disable-features=NetworkService,NetworkServiceInProcess",
"start-maximized",
"disable-infobars"
);
In addition, I have implemented a wait statement in my test scenario to provide ample time for the content to load:
final WebDriverWait wait = new WebDriverWait(driver, Duration.ofMinutes(1L));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("div_1_content")));
Despite multiple attempts, the issue of the content not loading persists even after the designated waiting period. Uncertain about the next course of action - could there be an error in my usage of Selenium? Might the content loading mechanism in the JS require alteration?
For further context, here is how I am approaching the page loading process in Selenium:
// Initialize driver
final ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
options.addArguments("--headless=new");
final URL url = new URL(http://127.0.0.1:4444/wd/hub);
final RemoteWebDriver driver= new RemoteWebDriver(url, options);
// Load page
driver.navigate().to("https://127.0.0.1:81");
// Await dynamic content retrieval
final WebDriverWait wait = new WebDriverWait(driver, Duration.ofMinutes(1L));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("div_1_content")));