[英]java.net.MalformedURLException: unknown protocol: maps
I am getting Exception in Selenium Webdriver (Java)我在 Selenium Webdriver (Java) 中遇到异常
java.net.MalformedURLException: unknown protocol: maps java.net.MalformedURLException:未知协议:地图
While Checking all Active Links(URLs) present on the page在检查页面上存在的所有活动链接(URL)时
The Code is as follows:代码如下:
for(int j=0;j<activeLinks.size();j++)
{
String strURL = activeLinks.get(j).getAttribute("href");
HttpURLConnection connection = (HttpURLConnection)newURL(activeLinks.get(j).getAttribute("href")).openConnection();
connection.connect();
String response = connection.getResponseMessage(); //ok
connection.disconnect();
System.out.println(activeLinks.get(j).getAttribute("href")+"--> " +response);
}
I suggest you check if http/https protocol is present for each href and add it if not.我建议您检查每个 href 是否存在 http/https 协议,如果没有则添加它。
ex:前任:
activeLinks.forEach(link -> {
String strURL = link.getAttribute("href");
strUrl = strUrl.startsWith("http") ? strUrl : "https://".concat(strUrl);
HttpURLConnection connection = (HttpURLConnection) new URL(strUrl).openConnection();
connection.connect();
String response = connection.getResponseMessage(); //ok
connection.disconnect();
System.out.println(String.format("%s --> %S", strUrl,response));
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.