Der Selenium -Treiber wartet nicht darauf, dass die Seite Java für mermaid.js lädtJava

Java-Forum
Anonymous
 Der Selenium -Treiber wartet nicht darauf, dass die Seite Java für mermaid.js lädt

Post by Anonymous »

Ich möchte mermaid.js verwenden, um ein Flussdiagramm zu rendern. Ich möchte den Selenium -Treiber in Java verwenden, um den gerenderten HTML Dom zu lesen. Die HTML -Quelle wird jedoch gelesen, wenn das Rendering nicht vollständig ist. Wie kann ich es erreichen? Code ">

Code: Select all





import mermaid from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
const config = {
startOnLoad: true,
flowchart: { useMaxWidth: true, htmlLabels: true, curve: 'cardinal' },
securityLevel: 'loose',
};
mermaid.initialize(config);




flowchart TD
A --> B


< /code>
< /div>
< /div>
< /p>
Java -Code: < /p>
package com.tugalsan.tst.html;

import static java.lang.System.out;
import java.nio.file.Path;
import java.time.Duration;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Main {

public static void main(String...  args) {
var urlPath = Path.of("C:\\git\\tst\\com.tugalsan.tst.html\\a.html");
var urlStr = urlPath.toUri().toString();
var until = Duration.ofMinutes(1);
var output = processHTML(urlStr, until, false, false);
out.println(output);
}

public static String processHTML(String urlStr, Duration until, boolean useFirefox, boolean useWait) {
WebDriver driver = null;
if (useFirefox) {
try {
//                    WebDriverManager.firefoxdriver().setup();
var options = new FirefoxOptions();
options.addArguments("--no-sandbox");
//                    options.setExperimentalOption("useAutomationExtension", false);
//                    options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
options.addArguments("--disable-infobars"); // disabling infobars
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--disable-popup-blocking");
options.setAcceptInsecureCerts(true);
//                    options.addArguments("--disable-blink-features=AutomationControlled");
driver = new FirefoxDriver(options);
if (useWait) {
waitForPageToLoad(driver, until);
}
driver.get(urlStr);
return driver.getPageSource();
} finally {
if (driver != null) {
driver.close();
}
if (driver != null) {
driver.quit();
}
}
}

var options = new EdgeOptions();
options.addArguments("--no-sandbox");
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
options.addArguments("--disable-infobars"); // disabling infobars
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--disable-popup-blocking");
options.setAcceptInsecureCerts(true);
options.addArguments("--disable-blink-features=AutomationControlled");

try {
driver = new EdgeDriver(options);
if (useWait) {
waitForPageToLoad(driver, until);
}
driver.manage().timeouts().implicitlyWait(until);
driver.manage().timeouts().pageLoadTimeout(until);
var dmn = new Dimension(1280, 1024);
driver.manage().window().setSize(dmn);
driver.get(urlStr);
return driver.getPageSource();
} finally {
if (driver != null) {
driver.close();
}
if (driver != null) {
driver.quit();
}
}
}

public static void waitForPageToLoad(WebDriver driver, Duration until) {
ExpectedCondition< Boolean> pageLoad = (WebDriver driver1) -> ((JavascriptExecutor) driver1).executeScript("return document.readyState").equals("complete");
Wait< WebDriver> wait = new WebDriverWait(driver, until);
try {
wait.until(pageLoad);
} catch (Throwable pageLoadWaitError) {
throw new RuntimeException(pageLoadWaitError);
}
}

}
< /code>
HTML-Ausgabe: < /p>



import mermaid from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'











Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post