线程“主”中的异常java.lang.ClassCastException:sun.net.www.protocol.mailto.MailToURLConnection无法转换为java.net.HttpURLConnection

时间:2019-08-26 10:14:54

标签: java selenium selenium-webdriver httpconnection

我试图在eclipse中运行下面的代码,它可以正常工作,但是在某些网站上运行时出现错误。 线程“主”中的异常java.lang.ClassCastException:sun.net.www.protocol.mailto.MailToURLConnection无法转换为java.net.HttpURLConnection。 我在代码中使用了httpconnection import语句,

    List <WebElement> linkslist = driver.findElements(By.tagName("a"));
    linkslist.addAll(driver.findElements(By.tagName("img")));
    System.out.println("size of full links and images --->" +linkslist.size());     
    List <WebElement> activelinks = new ArrayList <WebElement> ();      for(int i=0; i<linkslist.size(); i++)
    {
    if (linkslist.get(i).getAttribute("href")!= null && (!linkslist.get(i).getAttribute("href").contains("javascript")))
    {
    activelinks.add(linkslist.get(i));
                }               
            }
    System.out.println("size of active links and images --->" + activelinks.size());
    for(int j=0; j<activelinks.size(); j++)
            {   
HttpURLConnection connection = (HttpURLConnection) new URL(activelinks.get(j).getAttribute("href")).openConnection() ;              connection.connect();           
    String response = connection.getResponseMessage();
    connection.disconnect();
    System.out.println(activelinks.get(j).getAttribute("href") + "--->" + response+connection.getResponseCode());              
            }       
    linkslist.clear();
    activelinks.clear();

0 个答案:

没有答案