2016-05-15 55 views
0

请协助我使用eclipse设置htmlunit。我tryning填写的表格,并通过代码无法在eclipse中设置HTMLUNIT

这里提交这是我的代码

import com.gargoylesoftware.htmlunit.WebClient; 
import com.gargoylesoftware.htmlunit.html.HtmlForm; 
import com.gargoylesoftware.htmlunit.html.HtmlPage; 
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; 
import com.gargoylesoftware.htmlunit.html.HtmlTextInput; 

public class Ullas { 


     public static void main(String[] args) { 

      WebClient client = new WebClient(); 
      try 
      { 
       HtmlPage currentPage = (HtmlPage)client.getPage("http://xx.com"); 
       HtmlForm form = (HtmlForm) CurrentPage.getElementById("login_form"); 
       final HtmlTextInput textField = form.getInputByName("nm"); 
       textField.setValueAttribute("mak"); 
       final HtmlSubmitInput button = form.getInputByName("submitbutton"); 

       //currentPage = form.getAcceptAttribute(); 

       button.click(); 
      } 
      catch(Exception ex) 
      { 
       System.out.println("Some form of error happened !"); 
      } 


     } 

} 

我没有包括所有的图书馆,但是当我运行它口口声声说应用的”用户操作等待'建筑工作区'太完整了'

+0

Eclipse可以有有时挂,没有明显的趋势原因(通常是因为记忆力)。尝试重新启动应用程序,如果你已经做到了;问题是否存在? – PseudoAj

+0

问题已解决,但您能解释我上面的代码应该如何工作意味着它应该弹出页面后表单submited或什么,因为当我执行我的代码。它什么都不做 –

+0

上面的代码打开一个网页,输入文本并点击提交按钮。我假设你已经将它指向了正确的域,那么它应该显示结果。 – PseudoAj

回答

0

Eclipse有这种奇怪的倾向(经常由于内存)。大多数情况下重新启动您的实例可以解决问题。或者,运行eclipse.exe -clean也应该解决问题,因为eclipse会在启动时清除所有缓存数据。该问题已报告几个用户,我附上供您参考链接:

https://www.genuitec.com/forums/topic/myeclipse-hangs-on-building-workspace-0/

User Operation is waiting for "Building Workspace"

https://www.eclipse.org/forums/index.php/t/512454/

https://bugs.eclipse.org/bugs/show_bug.cgi?id=77946