2015-12-17 116 views

回答

0

使用來檢查URL的響應代碼:

public static boolean getResponseCode(String chkurl) { 
     boolean validResponse = false; 
      try { 
       //Get response code of URL 
       HttpResponse urlresp = new DefaultHttpClient().execute(new HttpGet(chkurl)); 
       int resp_Code = urlresp.getStatusLine().getStatusCode(); 
       System.out.println("Response Code Is : "+resp_Code +" for "+chkurl); 
       if ((resp_Code == 404) || (resp_Code == 505)) { 
        validResponse = false; 
        } else { 
        validResponse = true; 
        } 
       } catch (Exception e) { 
       } 
       return validResponse; 
      } 
0

恐怕也沒有辦法檢查做直接使用webdriver的HTTP狀態代碼。您可以直接使用HTTP客戶端,但如果問題是500代碼或403,則可能會變得笨拙。我們在本書中介紹了使用Mob Browser Proxy和WedDriver的更強大的技術:

http://selenium-webdriver-in-practice.github.io

相關問題