public void setJavascriptEnabled(boolean enableJavascript) { this.enableJavascript = enableJavascript; webClient.setJavaScriptEnabled(enableJavascript); }
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);
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);
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());
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);
webClient.setJavaScriptEnabled(true); webClient.setThrowExceptionOnScriptError(false); webClient.setRedirectEnabled(false);
//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();
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);
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 }
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); } } }
public static WebClient newWebClient(boolean isJavascriptEnabled) { WebClient webClient = new WebClient(); webClient.setRedirectEnabled(true); webClient.setCssEnabled(false); webClient.setJavaScriptEnabled(isJavascriptEnabled); return webClient; }
webClient.setJavaScriptEnabled(true); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.setJavaScriptTimeout(20000);
webClient.setJavaScriptEnabled(true);
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); }