2014-09-27 20 views
1

我正在使用Intranet網站。當我通過chrome或IE瀏覽器登錄到https://itam.flextron.com.au/arsys/shared/login.jsp網站時,它工作正常。但是,當我通過瀏覽器登錄到網站時,會彈出一個窗口並自動關閉,然後顯示登錄頁面。com.gargoylesoftware.html單元.ScriptException:調用開放的異常

但是當我通過HTMLUNIT訪問內部網頁時,它會拋出一些html代碼的異常。

公共類識別TestClass {

public static void homePage() throws Exception { 
    WebClient webClient = new WebClient(BrowserVersion.CHROME); 
    HtmlPage page = webClient.getPage("https://itam.flextron.com.au/arsys/shared/login.jsp"); 
    System.out.print("Accessing the webpage..."); 
    System.out.print(page.asText()); 
    webClient.closeAllWindows(); 
} 
public static void main(String arg[]) 
{ 
    try { 
     homePage(); 
    } 
    catch(Exception e) 
    { 
     System.out.print("Exception : "+ e); 
    } 
} 

}

**

例外:

**

Sep 27, 2014 11:47:17 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 
 
WARNING: Obsolete content type encountered: 'application/x-javascript'. 
 
Sep 27, 2014 11:47:17 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary 
 
INFO: statusCode=[404] contentType=[text/html] 
 
Sep 27, 2014 11:47:17 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary 
 
INFO: 
 
<HTML> 
 

 
<HEAD> 
 
<title>BMC&nbsp;Remedy&nbsp;Mid&nbsp;Tier&nbsp;7.1 - Error page</title><!--;--> 
 
<style type="text/css"> 
 
    <!-- 
 
    BODY  {font-family:Tahoma,arial,helvetica,verdana;} 
 
    .ErrorTitle {font-size:12pt; font-weight:bold; text-align:left;} 
 
    .ErrorMsg {font-size:12pt; text-align:left;} 
 
    .ReturnHome {font-size:10pt;} 
 
#product {position: absolute; top:20px; left: 0px; font: 16px "Arial", "Lucida Grande", "Verdana", "Helvetica", sans-serif; font-weight: bold; color: #ffffff; padding-left:18px; text-align:left;} 
 
#logo {position: absolute; top:15px; right:0px} 
 
    --> 
 
</style> 
 
<script> 
 
function setOverride(yesno) { 
 
    document.overrideForm.ipoverride.value = yesno; 
 
    document.overrideForm.submit(); 
 
} 
 

 

 
</script> 
 
</HEAD> 
 

 
<BODY style="background-repeat: no-repeat" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
 

 
<table border=0 cellpadding="0" cellspacing="0" width="100%"> 
 
\t <!-- header table --> 
 
\t <tr> 
 
\t \t <td width="100%"> 
 
\t \t \t <table border=0 cellpadding="0" cellspacing="0" width="100%" height=60> 
 
\t \t \t <tr> 
 
\t \t \t \t <td height=60 background="/arsys/shared/images/bkgd_image.gif"> 
 
\t \t \t \t <span id="product">&nbsp;</span> 
 
\t \t \t \t <div id="logo" align="right"> 
 
\t \t \t \t \t <img src="/arsys/shared/images/bmc_logo.gif" width="118" height="26" hspace="20" alt="BMC logo"> 
 
\t \t \t \t </div> 
 
\t \t \t \t </td> 
 
\t \t \t </tr> 
 
\t \t \t </table> 
 
\t \t </td> 
 
\t </tr> 
 
</table> 
 

 
<br> 
 
<br> 
 
<br> 
 
<br> 
 
<table> 
 
<tr> 
 
<td width=150 nowrap> 
 
    &nbsp; 
 
</td> 
 
<td> 
 
    
 
     <div class="ErrorTitle"> 
 
     The following error(s) occurred while trying to process your request:<!--;--> 
 
     </div> 
 
     <br> 
 
     <br> 
 
     
 
      <div class="ErrorMsg"> 
 
      ARERR&nbsp;[9217] 
 
      <br> 
 
      File not found. Either the file requested is not present or the URL supplied is bad.&nbsp; 
 
      </div> 
 
      <br><br> 
 
      
 
</td> 
 
</tr> 
 

 
<tr> 
 
<td width=150 nowrap> 
 
&nbsp; 
 
</td> 
 
<td class="ReturnHome"> 
 

 
     <a href=/arsys/home>Return to home page</a> 
 

 
</td> 
 
</tr> 
 
</table> 
 
<script> 
 

 
var Msg="File not found. Either the file requested is not present or the URL supplied is bad.\n" 
 
</script> 
 

 
</BODY> 
 
</HTML> 
 

 
Exception: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking open

回答

0

問題可能是代碼運行到一些JavaScript,這HtmlUnitDriver默認情況下不支持。嘗試是這樣的:

HtmlUnitDriver driver = new HtmlUnitDriver; 
    driver.SetJavaScriptEnabled(true); 

如果不工作,你基本上可以運行其他瀏覽器,通過HtmlUnitDriver這樣不支持JS:

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6); 
    driver.setJavascriptEnabled(true);