2013-09-01 2 views
4

www.meetme.com에서 메시지를 보내려고하지만이를 수행하는 방법을 알 수 없습니다. 댓글 영역에 메시지를 입력 할 수 있지만 보내기 버튼을 클릭해도 아무런 변화가 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 로그인하고 로그인 버튼을 누르면 페이지가 바뀌고 모든 것이 정상입니다. 누구든지 아이디어 나 단서가 있습니까?HtmlUnit 버튼을 클릭하십시오.

HtmlPage htmlPage = null; 
    HtmlElement htmlElement; 
    WebClient webClient = null; 
    HtmlButton htmlButton; 
    HtmlForm htmlForm; 
    try{ 

     // Create and initialize WebClient object 
     webClient = new WebClient(BrowserVersion.FIREFOX_17); 
     webClient.setCssEnabled(false); 
     webClient.setJavaScriptEnabled(false); 
     webClient.setThrowExceptionOnFailingStatusCode(false); 
     webClient.setThrowExceptionOnScriptError(false); 
     webClient.getOptions().setThrowExceptionOnScriptError(false); 
     webClient.getOptions().setUseInsecureSSL(true); 
     webClient.getCookieManager().setCookiesEnabled(true); 

     /*webClient.setRefreshHandler(new RefreshHandler() { 
      public void handleRefresh(Page page, URL url, int arg) throws IOException { 
       System.out.println("handleRefresh"); 
      } 

     });*/ 

     htmlPage = webClient.getPage("http://www.meetme.com"); 
     htmlForm = htmlPage.getFirstByXPath("//form[@action='https://ssl.meetme.com/login']"); 

     htmlForm.getInputByName("username").setValueAttribute("[email protected]"); 
     htmlForm.getInputByName("password").setValueAttribute("blah"); 

     //Signing in 
     htmlButton = htmlForm.getElementById("login_form_submit"); 
     htmlPage = (HtmlPage) htmlButton.click(); 

     htmlPage = webClient.getPage("http://www.meetme.com/member/1234567890"); 

     System.out.println("BEFORE CLICK"); 
     System.out.println(htmlPage.asText()); 


     //type message in text area 
     HtmlTextArea commentArea = (HtmlTextArea)htmlPage.getFirstByXPath("//textarea[@id='profileQMBody']"); 
     commentArea.setText("Testing");   


     htmlButton = (HtmlButton) htmlPage.getHtmlElementById("profileQMSend"); 
     htmlPage = (HtmlPage)htmlButton.click(); 
     webClient.waitForBackgroundJavaScript(7000); 

     //The print is exactly the same as the BEFORE CLICK print 
     System.out.println("AFTER CLICK"); 
     System.out.println(htmlPage.asText()); 

     }catch(ElementNotFoundException e){ 
     e.printStackTrace(); 
     }catch(Exception e){ 
     e.printStackTrace(); 
     } 

답변

3

액세스중인 웹 페이지에 대해 많이 알지 못하면 JavaScript를 사용하지 않고 AJAX 요청을 수행 할 수 없습니다. 변경이 성공하지 못하면 디버깅을 계속해야하지만 자바 스크립트가 활성화되어 있는지 확인해야합니다.

또한 HtmlUnit 1.12를 사용하고 코드에서 사용되지 않는 모든 메소드를 업데이트해야합니다.

나는 또한 JavaScript 경고를 해제 할 수 있습니다. 어떻게 할 수 있는지 보려면 this answer을 확인하십시오.

+1

@mostly 작동했습니다! 고마워요! – altoids

+0

환영합니다 :) 끔찍한 결과를 제거하려면 대답의 링크를 확인하십시오. (그 대답은 약간 구식 이었으므로 링크를 업데이트해야했습니다) –

관련 문제