HtmlForm form = page.getforms(0); form.getInputByName("name"); form.getInputByValue("value");
HtmlForm form = page.getForms().get(0); HtmlTextArea textArea = form.getTextAreaByName("scandata"); HtmlSubmitInput button = form.getInputByValue("Submit"); HtmlPage res = button.click(); int input_length = page.getByXPath("//input").size(); int tries = 5; while (tries > 0 && input_length < 12) { //you can change number of tries and condition according to your need tries--; synchronized (page) { page.wait(2000); //wait } input_length = page.getByXPath("//input").size(); //input length is example of condtion }
HtmlForm form = page.getForms().get(0); HtmlTextArea textArea = form.getTextAreaByName("scandata"); HtmlSubmitInput button = form.getInputByValue("Submit"); HtmlPage res = button.click(); int input_length = page.getByXPath("//input").size(); int tries = 5; while (tries > 0 && input_length < 12) { //you can change number of tries and condition according to your need tries--; synchronized (page) { page.wait(2000); //wait } input_length = page.getByXPath("//input").size(); //input length is example of condtion }
HtmlPage page = (HtmlPage) webClient.getPage("https:website name.com/loginpage"); HtmlForm form = page.getFormBy("login_form"); HtmlForm formm= page.getForms().get(0); formm.getInputByName("SignInEmailAddress").setValueAttribute("your emailid"); formm.getInputByName("SignInPassword").setValueAttribute("password"); page = (HtmlPage) formm.getInputByValue("Login").click(); System.out.println(page); System.out.println(page.asText());
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); WebClient client = new WebClient(BrowserVersion.CHROME); client.getOptions().setJavaScriptEnabled(true); client.getOptions().setThrowExceptionOnScriptError(false); client.getOptions().setThrowExceptionOnFailingStatusCode(false); String url = "http://lsa.colorado.edu/cgi-bin/LSA-pairwise.html"; final HtmlPage page = client.getPage(url); HtmlForm htmlForm = page.getForms().get(0); HtmlTextArea txtA = htmlForm.getTextAreaByName("txt1"); txtA.setText("hello"); HtmlSubmitInput submitBt = htmlForm.getInputByValue("Submit Texts"); // change the form action attribute to the correct one htmlForm.setAttribute("action", "http://lsa.colorado.edu/cgi-bin/LSA-pairwise-x.html"); HtmlPage page2 = submitBt.click(); System.out.println(page2.asText());
public class FormSubmit { public static void main(String[] args) throws Exception { try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { final HtmlPage page1 = webClient.getPage("https://applicazioni.gse.it/GWA_UI/"); System.out.println(page1.asXml()); final HtmlForm form = page1.getFormByName("aspnetForm"); final HtmlTextInput username = form.getInputByName("ctl00$ctl00$cphFormAppl$cphRisultatiRicerca$txtUserid"); username.setValueAttribute("namevalue"); final HtmlPasswordInput password = form.getInputByName("ctl00$ctl00$cphFormAppl$cphRisultatiRicerca$txtPassword"); password.setValueAttribute("passvalue"); final HtmlPage page2 = (HtmlPage) form.getInputByValue(" Login ").click(); System.out.println(page2.asText()); } } }
try (WebClient webClient = new WebClient()) { HtmlPage page = (HtmlPage) webClient.getPage("https://ma-andover.myfollett.com/aspen/logon.do"); HtmlForm form = page.getFormByName("logonForm"); form.getInputByName("username").type("myUsername"); form.getInputByName("password").type("myPassword"); page = form.getInputByValue("Log On").click(); System.out.println(page.asText()); }
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 }
HtmlPage page3; page3 = webClient.getPage("Website"); HtmlForm loginForm = page3.getFormByName("loginForm"); HtmlTextInput username = loginForm.getInputByName("NameofUsernameElement"); HtmlPasswordInput pass = loginForm.getInputByName("NameofPassowordElement"); HtmlSubmitInput b = loginForm.getInputByValue("LoginButtonValue"); username.setValueAttribute("Actualy Username"); pass.setValueAttribute("Actual Password"); HtmlPage page2; page2 = b.click();
//set browser WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10); //not to throw exception on javascript error webClient.setThrowExceptionOnScriptError(false); //set page to access final HtmlPage homepageEn = webClient.getPage("http://protein.rnet.missouri.edu:8080/MongoTest/"); //get the form by id HtmlForm form = homepageEn.getFirstByXPath("//form[@id='input_form']"); //setup the fields to use HtmlTextInput mailField = form.getInputByName("mail"); HtmlPasswordInput passwordField = form.getInputByName("password"); //define the submit button (defined by value) HtmlSubmitInput submitButton = form.getInputByValue("submit"); //change the value of text fields mailField.setValueAttribute("somemail@xyzmail.com"); passwordField.setValueAttribute("some_password"); //finally submit the form by clicking the button final HtmlPage resultsPage = submitButton.click();
public static void main(String[] args) { WebClient webClient = new WebClient(); try { HtmlPage page = (HtmlPage) webClient .getPage("https://ma-andover.myfollett.com/aspen/logon.do"); HtmlForm form = page.getFormByName("logonForm"); form.getInputByName("username").setValueAttribute("myUsername"); HtmlInput passWordInput = form.getInputByName("password"); passWordInput.removeAttribute("disabled"); passWordInput.setValueAttribute("myPassword"); page = form.getInputByValue("Log On").click(); // works fine System.out.println(page.asText()); } catch (Exception e) { e.printStackTrace(); } finally { webClient.close(); } }
WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://some_host/test.html"); HtmlForm form = page.getForms().get(0); form.getInputByName("username").setValueAttribute(username); form.getInputByName("password").setValueAttribute(password); form.getInputByName("pict_to").setValueAttribute("0"); form.getInputByName("pict_type").setValueAttribute("0"); form.getInputByName("pict").setValueAttribute("full_path_to_captcha_png"); form.<HtmlFileInput>getInputByName("pict").setContentType("image/png");//optional HtmlPage page2 = form.getInputByValue("Send").click();
HtmlRadioButtonInput swallow = form.getInputByValue(SWALLOW); swallow.click(); HtmlSubmitInput submit = form.getInputByValue("here");