打开网址,有几个输入框,鼠标指进去,输入完,失去焦点的时候做个验证。
请问怎么用HtmlUnit模拟呢
谢谢了!
3 个解决方案
#1
HtmlUnit不了解,帖子帮你顶上去了。
#2
import java.io.IOException;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class TestMain {
public static void main(String[] args) throws IOException {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page = client.getPage("http://www.kaixin001.com");
HtmlElement elmt = page.getElementByName("email");
//elmt.mouseOut();
//elmt.mouseOver();
elmt.click();
elmt.type("用户名");
System.out.println(elmt.getTextContent());
HtmlElement elmt1 = page.getElementByName("password");
elmt1.click();
elmt1.type("密码");
// HtmlButton loginBtn = (HtmlButton)page.getElementById("btn_dl");
Page resultPage = page.getElementById("btn_dl").click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(resultPage.getWebResponse().getContentAsString());
}
}
看到
//elmt.mouseOut();
//elmt.mouseOver();
elmt.click();
了吧,不用解释了吧。
#3
真是很感谢,讲解的很详细,就是我想知道的!
#1
HtmlUnit不了解,帖子帮你顶上去了。
#2
import java.io.IOException;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class TestMain {
public static void main(String[] args) throws IOException {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page = client.getPage("http://www.kaixin001.com");
HtmlElement elmt = page.getElementByName("email");
//elmt.mouseOut();
//elmt.mouseOver();
elmt.click();
elmt.type("用户名");
System.out.println(elmt.getTextContent());
HtmlElement elmt1 = page.getElementByName("password");
elmt1.click();
elmt1.type("密码");
// HtmlButton loginBtn = (HtmlButton)page.getElementById("btn_dl");
Page resultPage = page.getElementById("btn_dl").click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(resultPage.getWebResponse().getContentAsString());
}
}
看到
//elmt.mouseOut();
//elmt.mouseOver();
elmt.click();
了吧,不用解释了吧。
#3
真是很感谢,讲解的很详细,就是我想知道的!