Java使用Selenium自动化测试网盘链接是否失效
欢迎来到我的小屋
1、使用依赖
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
2、Selenium简单教程
System.setProperty("webdriver.edge.driver", "msedgedriver.exe");//设置edge驱动
WebDriver driver = new EdgeDriver();
driver.get("https://quark.sm.cn/s/123456789012");
driver.quit();
3、Selenium自动化测试网盘链接是否失效
以夸克网盘链接为例:https://quark.sm.cn/s/123456789012
driver.get(url);
try {
// 使用 WebDriverWait 等待页面加载,检查两种可能的元素
WebDriverWait wait = new WebDriverWait(driver, 4);
// 等待任意一个元素出现
ExpectedCondition<Boolean> elementCondition = ExpectedConditions.or(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.ShareError--content--38P8Js9")),
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.filename-text")),
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input.ant-input"))
);
wait.until(elementCondition);
if (!driver.findElements(By.cssSelector("div.ShareError--content--38P8Js9")).isEmpty()) {
log("URL: " + url + " 链接失效!!!!!!", logArea);
errorUrls.add(url);
} else if (!driver.findElements(By.cssSelector("div.filename-text")).isEmpty()) {
log("URL: " + url + " 链接有效", logArea);
} else if (!driver.findElements(By.cssSelector("input.ant-input")).isEmpty()) {
log("URL: " + url + " 链接有效", logArea);
}
} catch (org.openqa.selenium.TimeoutException e) {
log("URL: " + url + " 链接可能失效", logArea);
errorUrls.add(url);
}

Java使用Selenium自动化测试网盘链接是否失效
浙公网安备 33010602011771号