【发布时间】:2018-11-04 00:19:25
【问题描述】:
有没有办法测试我的硬盘上的本地 html 文件的链接是否有效?我有几个 *.htm 文件,我在其中搜索文档中的所有链接。我正在搜索所有链接元素以及来自元素的 href 属性的链接。我尝试使用 silenium 和 HttpURLConnection 测试有效链接,但我想测试的 href 目标采用 file:///C://root//example.htm 的形式。这对我不起作用,因为它是一个本地文件并且我得到了 CastException:
URL url = new URL("file:///C://root//example.htm");
HttpURLConnection httpURLConnect = (HttpURLConnection) url.openConnection();
httpURLConnect.setConnectTimeout(1500);
httpURLConnect.connect();
if(httpURLConnect.getResponseCode() == 200)
{
System.out.println(href + " - " + httpURLConnect.getResponseMessage());
}
【问题讨论】:
标签: java html testing selenium-webdriver hyperlink