该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
htmlunit版本2.13
尝试打开google,在文本框中输入关键字,按提交按钮搜索,页面可以跳转。而登陆yahoo邮箱,人人,click()方法调用后页面没有跳转
代码如下:
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class setFormforversion3 {
public static void main(String[] args){
try{
WebClient client = new WebClient(BrowserVersion.FIREFOX_10);
HtmlPage page = client.getPage("http://www.renren.com");
HtmlForm form = page.getForms().get(0);
System.out.println(form);
HtmlTextInput textID = form.getInputByName("email");
HtmlPasswordInput textPW = form.getInputByName("password");
HtmlSubmitInput submit = form.getInputByValue("登录人人网");
textID.setValueAttribute("some@gmail.com");
textPW.setValueAttribute("somepassword");
page = submit.click();
System.out.println(page.getUrl());
System.out.println(page.asXml());
}catch(Exception e){
e.printStackTrace();
System.out.println("error?");
}
}
}
不知道什么原因,求大神解答