java.net.MalformedURLException:未知协议:映射

java.net.MalformedURLException:未知协议:映射,java,selenium,automation,webdriver,Java,Selenium,Automation,Webdriver,我在SeleniumWebDriver(Java)中遇到异常 java.net.MalformedURLException:未知协议:映射 检查页面上存在的所有活动链接(URL)时 代码如下: for(int j=0;j<activeLinks.size();j++) { String strURL = activeLinks.get(j).getAttribute("href"); HttpURLConnection connection = (HttpURLConne

我在SeleniumWebDriver(Java)中遇到异常

java.net.MalformedURLException:未知协议:映射

检查页面上存在的所有活动链接(URL)时

代码如下:

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);
}

for(int j=0;j我建议您检查每个href是否存在http/https协议,如果没有,则添加它

例:

activeLinks.forEach(link->{
字符串strURL=link.getAttribute(“href”);
strUrl=strUrl.startsWith(“http”)?strUrl:“https://”。concat(strUrl);
HttpURLConnection connection=(HttpURLConnection)新URL(strUrl).openConnection();
connection.connect();
字符串响应=连接。getResponseMessage();//确定
连接断开();
System.out.println(String.format(“%s-->%s”,strUrl,response));
})

我建议您检查每个href是否存在http/https协议,如果没有,请添加它

例:

activeLinks.forEach(link->{
字符串strURL=link.getAttribute(“href”);
strUrl=strUrl.startsWith(“http”)?strUrl:“https://”。concat(strUrl);
HttpURLConnection connection=(HttpURLConnection)新URL(strUrl).openConnection();
connection.connect();
字符串响应=连接。getResponseMessage();//确定
连接断开();
System.out.println(String.format(“%s-->%s”,strUrl,response));
})

哪行抛出错误?我怀疑这是一个铸造问题,与Selenium无关。哪行抛出错误?我怀疑这是一个铸造问题,与Selenium无关