You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.0 KiB

10 months ago
package Tools.DataEase;
10 months ago
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
10 months ago
import java.io.IOException;
10 months ago
import java.time.Duration;
10 months ago
public class TestRead {
public static void main(String[] args) throws IOException {
10 months ago
String url = "http://10.10.14.203/#/de-link/NtXhclS0";
// 设置ChromeDriver的路径
//System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
// 初始化Chrome浏览器
WebDriver driver = new FirefoxDriver();
// 打开目标URL
driver.get(url);
// 显式等待等待页面中特定元素加载完成例如等待一个特定的div加载完成
//WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(600)); // 10秒超时时间
//WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("element-id")));
// 等待页面加载完成
new WebDriverWait(driver, Duration.ofSeconds(600)).until(webDriver ->
((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete")
);
// 获取渲染后的HTML内容
String renderedHtml = driver.getPageSource();
// 输出渲染后的HTML内容
renderedHtml= renderedHtml.replace("./assets","http://10.10.14.203/assets");
renderedHtml= renderedHtml.replace("./js/","http://10.10.14.203/js/");
renderedHtml= renderedHtml.replace("./dataease.svg","http://10.10.14.203/dataease.svg");
10 months ago
10 months ago
System.out.println(renderedHtml);
//href="./assets
// 关闭浏览器
driver.quit();
10 months ago
}
}