use of com.gargoylesoftware.htmlunit.WebClient in project javaee7-samples by javaee-samples.
the class SecureServletTest method setup.
@Before
public void setup() {
correctCreds.addCredentials("u1", "p1");
incorrectCreds.addCredentials("random", "random");
webClient = new WebClient();
}
use of com.gargoylesoftware.htmlunit.WebClient in project javaee7-samples by javaee-samples.
the class SecureServletTest method setup.
@Before
public void setup() {
correctCreds.addCredentials("u1", "p1");
incorrectCreds.addCredentials("random", "random");
webClient = new WebClient();
}
use of com.gargoylesoftware.htmlunit.WebClient in project javaee7-samples by javaee-samples.
the class FormTest method setup.
@Before
public void setup() throws IOException {
@SuppressWarnings("resource") WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(base + "SecureServlet");
loginForm = page.getForms().get(0);
}
use of com.gargoylesoftware.htmlunit.WebClient in project yyl_example by Relucent.
the class HtmlUnitTest1 method main.
public static void main(String[] args) {
// 得到浏览器对象
WebClient webClient = null;
try {
webClient = new WebClient();
webClient.waitForBackgroundJavaScript(60 * 1000);
WebClientOptions options = webClient.getOptions();
// 不加载css
options.setCssEnabled(true);
// 启用JS解释器,默认为true
options.setJavaScriptEnabled(false);
options.setUseInsecureSSL(true);
// options.setRedirectEnabled(true);
// 当出现HttpError时,是否抛出异常
options.setThrowExceptionOnFailingStatusCode(false);
// JS运行错误时,是否抛出异常
options.setThrowExceptionOnScriptError(false);
// 设置AJAX异步处理控制器(启用AJAX支持)
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
// 拿到网页
HtmlPage htmlpage = webClient.getPage("http://news.baidu.com/advanced_news.html");
// 根据名字得到表单(表单的名字叫“f”)
HtmlForm form = htmlpage.getFormByName("f");
System.out.println(form);
// 获取“百度一下”这个按钮
HtmlSubmitInput button = form.getInputByValue("百度一下");
System.out.println(button);
// 得到搜索框
HtmlTextInput textField = form.getInputByName("q1");
System.out.println(textField);
// 在搜索框内填入“HtmlUnit”
textField.setValueAttribute("HtmlUnit");
// 点击按钮
HtmlPage nextPage = button.click();
// 下一个页面
System.out.println(nextPage);
// 获得页面结果
String result = nextPage.asXml();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (webClient != null) {
webClient.close();
}
}
}
use of com.gargoylesoftware.htmlunit.WebClient in project yyl_example by Relucent.
the class HtmlUnitTest2 method main.
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_68);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setRedirectEnabled(false);
webClient.getOptions().setAppletEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setTimeout(10000);
// JS运行错误时,是否抛出异常
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage page = webClient.getPage("http://huaban.com/favorite/home/");
System.out.println(page.asXml());
webClient.close();
}
Aggregations