本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.setJavaScriptEnabled()
方法的一些代码示例,展示了WebClient.setJavaScriptEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.setJavaScriptEnabled()
方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:setJavaScriptEnabled
[英]Enables/disables JavaScript support. By default, this property is enabled.
[中]启用/禁用JavaScript支持。默认情况下,此属性处于启用状态。
代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit
public void setJavascriptEnabled(boolean enableJavascript) {
this.enableJavascript = enableJavascript;
webClient.setJavaScriptEnabled(enableJavascript);
}
代码示例来源:origin: stackoverflow.com
BrowserVersionFeatures[] bvf = new BrowserVersionFeatures[1];
bvf[0] = BrowserVersionFeatures.HTMLIFRAME_IGNORE_SELFCLOSING;
BrowserVersion bv = new BrowserVersion(
BrowserVersion.NETSCAPE, "5.0 (Windows; en-US)",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8",
(float) 3.6, bvf);
WebClient webClient = new WebClient(bv);
webClient.setJavaScriptEnabled(true);
代码示例来源:origin: stackoverflow.com
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
try
{
final WebClient webClient = new WebClient( BrowserVersion.FIREFOX_3 );
webClient.setJavaScriptEnabled( false ) ;
final HtmlPage page = webClient.getPage("http://www.google.com");
tv.setText( page.asText().substring( 0, 50 ) );
}
catch( Throwable t )
{
tv.setText(t.getMessage());
}
setContentView(tv);
代码示例来源:origin: stackoverflow.com
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
webClient.setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage("http://www.google.com/ncr");
ScriptResult scriptResult = page.executeJavaScript("document.title");
System.out.println(scriptResult.getJavaScriptResult());
代码示例来源:origin: stackoverflow.com
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setTimeout(60000);
client.setRedirectEnabled(true);
client.setJavaScriptEnabled(true);
client.setThrowExceptionOnFailingStatusCode(false);
client.setThrowExceptionOnScriptError(false);
client.setCssEnabled(false);
client.setUseInsecureSSL(true);
代码示例来源:origin: stackoverflow.com
webClient.setJavaScriptEnabled(true);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRedirectEnabled(false);
代码示例来源:origin: stackoverflow.com
//for chrome simulation
WebClient webClient = new WebClient(BrowserVersion.CHROME_16);
//has getting an error from [http://www.google-analytics.com/ga.js with javascript on.
webClient.setJavaScriptEnabled(false);
HtmlPage page = webClient.getPage("http://yourtargetpage/Default.aspx");
//get the form by name, check page source for name
HtmlForm form = page.getFormByName("aspnetForm");
HtmlPasswordInput inputPass = form.getInputByName("your input password text field name");
HtmlTextInput userName = form.getInputByName("your input user text field name");
HtmlSubmitInput button=form.getInputByName("your target submit button");
//set username and password
userName.setText("myuser");
inputPass.setText("mypassword");
//click the submit button and get the returned page
HtmlPage page2 = button.click();
代码示例来源:origin: stackoverflow.com
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setTimeout(60000);
client.setRedirectEnabled(true);
client.setJavaScriptEnabled(true);
client.setThrowExceptionOnFailingStatusCode(false);
client.setThrowExceptionOnScriptError(false);
client.setCssEnabled(false);
client.setUseInsecureSSL(true);
HtmlPage page = null;
try {
page = client.getPage("http://www.whatever.com");
} catch (Exception e) {
// TODO Auto-generated catch block
}
if (page.getWebResponse().getStatusCode() == 404) {
System.out.println("Page not found");
}
// Post a request
WebRequest request = new WebRequest(new URL("http://www.whatever.com/post_url"));
request.setHttpMethod(HttpMethod.POST);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("login", userLogin));
params.add(new NameValuePair("pass", userPassword));
request.setRequestParameters(params);
page = client.getPage(request);
代码示例来源:origin: stackoverflow.com
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
try{ final HtmlPage page1 = webClient.getPage("http://www.ccstechnologies.org/login.aspx/");
final HtmlForm form = page1.getFormByName("form1");
final HtmlSubmitInput button = form.getInputByName("BtnLogin");
final HtmlTextInput textField = form.getInputByName("Username");
final HtmlPasswordInput pwd = form.getInputByName("password");
textField.setValueAttribute("username");
pwd.setValueAttribute("password");
System.out.println(page1.asText());
final HtmlPage page2 = (HtmlPage) form.getInputByValue("Login").click();
String htmlBody = page2.getWebResponse().getContentAsString();
System.out.println(page2.asText());
System.out.println("Base Uri 1 : "+page1);
System.out.println("Base Uri 2 : "+page2);
webClient.closeAllWindows();}catch (Exception e) {
// TODO: handle exception
}
代码示例来源:origin: stackoverflow.com
public String getPageSourceFromBrowser(String url) throws SiteAnalizeException {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage firstPage = null;
String result = null;
try {
webClient.setJavaScriptEnabled(true);
webClient.setThrowExceptionOnScriptError(false);
webClient.setCssEnabled(false);
webClient.setUseInsecureSSL(false);
webClient.setRedirectEnabled(true);
firstPage = webClient.getPage(new URL(url));
result = firstPage.getWebResponse().getContentAsString("UTF-8");
DomNodeList<HtmlElement> button = firstPage.getElementsByTagName("a");
for (HtmlElement htmlElement : button) {
if(htmlElement.asText().equals("Buy Now")) {
HtmlPage page = htmlElement.click();
//HtmlElement button2 = page.getElementById("market_buynow_dialog_addfunds");
//HtmlPage page2 = button2.click();
String htmlBody = page.getWebResponse().getContentAsString();
System.out.println(htmlBody);
}
}
}
代码示例来源:origin: org.scribe/scribe-up
public static WebClient newWebClient(boolean isJavascriptEnabled) {
WebClient webClient = new WebClient();
webClient.setRedirectEnabled(true);
webClient.setCssEnabled(false);
webClient.setJavaScriptEnabled(isJavascriptEnabled);
return webClient;
}
代码示例来源:origin: stackoverflow.com
webClient.setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setJavaScriptTimeout(20000);
代码示例来源:origin: stackoverflow.com
webClient.setJavaScriptEnabled(true);
代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit
private WebClient createWebClient(BrowserVersion version) {
WebClient client = newWebClient(version);
client.setThrowExceptionOnFailingStatusCode(false);
client.setPrintContentOnFailingStatusCode(false);
client.setJavaScriptEnabled(enableJavascript);
client.setRedirectEnabled(true);
try {
client.setUseInsecureSSL(true);
} catch (GeneralSecurityException e) {
throw new WebDriverException(e);
}
// Ensure that we've set the proxy if necessary
if (proxyConfig != null)
client.setProxyConfig(proxyConfig);
return modifyWebClient(client);
}
内容来源于网络,如有侵权,请联系作者删除!