As the title indicate.
Simple example provided.
The code is just waiting for the download links to be available, hopefully you can point out what I'm doing wrong.
Thanks in advance! I used htmlunit to write simple unitests for my javascript api on a private project years ago and worked like a charm.
package test;
import org.htmlunit.BrowserVersion;
import org.htmlunit.WebClient;
import org.htmlunit.html.DomElement;
import org.htmlunit.html.DomNodeList;
import org.htmlunit.html.HtmlPage;
import org.junit.jupiter.api.Test;
public class JavascriptPageLoadTest {
private static final long TIMEOUT = 30000 * 6; // 30 seconds * 6 = 3 minutes;
@Test
public void parsePageNonMature() throws Exception {
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
webClient.getOptions().setScreenWidth(2560);
webClient.getOptions().setScreenWidth(1440);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setMaxInMemory(-1);
HtmlPage page = webClient.getPage("https://romhacking.com/hack/Muhly-64");
String pageAsXML = null;
while (pageAsXML == null) {
long start = System.currentTimeMillis();
if (System.currentTimeMillis() - start > TIMEOUT) {
throw new RuntimeException("Webpage load timeout.");
}
Thread.sleep(500);
DomNodeList<DomElement> links = page.getElementsByTagName("a");
pageAsXML = page.asXml();
if (!pageAsXML.contains("<a download href=")) {
pageAsXML = null;
}
}
System.out.println(pageAsXML);
}
}
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too