private List<HtmlForm> getForms() { HtmlPage page = (HtmlPage) win.getEnclosedPage(); return page.getForms(); }
/** * Return true if the current response contains a form. */ @Override public boolean hasForm() { return ((HtmlPage) win.getEnclosedPage()).getForms().size() > 0; }
private HtmlForm getForm(int formIndex) { return ((HtmlPage) win.getEnclosedPage()).getForms().get( formIndex); }
/** * <p>Return the form with the specified <code>id</code> from the most * recently retrieved page. If there is no such form, return * <code>null</code>.<p> * * @param id Identifier of the requested form. * * @exception Exception if an error occurs */ protected HtmlForm form(String id) throws Exception { Iterator forms = page.getForms().iterator(); while (forms.hasNext()) { HtmlForm form = (HtmlForm) forms.next(); if (id.equals(form.getAttributeValue("id"))) { return (form); } } return (null); }
/** * <p>Return the form with the specified <code>id</code> from the most * recently retrieved page. If there is no such form, return * <code>null</code>.<p> * * @param id Identifier of the requested form. * * @exception Exception if an error occurs */ protected HtmlForm form(String id) throws Exception { Iterator forms = page.getForms().iterator(); while (forms.hasNext()) { HtmlForm form = (HtmlForm) forms.next(); if (id.equals(form.getAttributeValue("id"))) { return (form); } } return (null); }
private HtmlForm getForm(String nameOrID, int index) { List<HtmlForm> forms = new ArrayList<HtmlForm>(); for (HtmlForm form : getCurrentPage().getForms()) { if (nameOrID.equals(form.getId()) || nameOrID.equals(form.getNameAttribute())) { forms.add(form); } } if (forms.size() > index) { return forms.get(index); } else { return null; } }
public SignupPage(HtmlPage signupPage) { this.signupPage = signupPage; assertNotNull("The sign up page has a username field.", this.signupPage.getElementById("username")); for (HtmlForm signupForm : this.signupPage.getForms()) { if (signupForm.getInputsByName("username").size() == 0) continue; this.signupForm = signupForm; } }
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());
private HtmlForm findForm(HtmlPage page, String action) { for (HtmlForm form: page.getForms()) { if (action.equals(form.getActionAttribute())) { return form; } } fail("no form found"); return null; }
//Get Page HtmlPage page1 = webClient.getPage("https://login-url/"); //Wait for background Javascript webClient.waitForBackgroundJavaScript(10000); //Get first form on page HtmlForm form = page1.getForms().get(0); //Get login input fields using input field name HtmlTextInput userName = form.getInputByName("UserName"); HtmlPasswordInput password = form.getInputByName("Password"); //Set input values userName.setValueAttribute("MyUserName"); password.setValueAttribute("MyPassword"); //Find the first button in form using name, id or xpath HtmlElement button = (HtmlElement) form.getFirstByXPath("//button"); //Post by clicking the button and cast the result, login arrival url, to a new page and repeat what you did with page1 or something else :) HtmlPage page2 = (HtmlPage) button.click(); //Profit System.out.println(page2.asXml());
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput email = form.getInputByName("Email"); email.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput passwd = form.getInputByName("Passwd"); passwd.setValueAttribute("testpwdscribeup34"); HtmlSubmitInput submit = form.getInputByName("signIn"); final HtmlPage confirmPage = submit.click(); form = confirmPage.getForms().get(0); submit = form.getInputByName("allow"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { HtmlForm form = authorizationPage.getForms().get(1); final HtmlTextInput login = form.getInputByName("login_email"); login.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput passwd = form.getInputByName("login_password"); passwd.setValueAttribute("testpwdscribeup"); HtmlSubmitInput submit = form.getInputByName("login_submit_dummy"); final HtmlPage confirmPage = submit.click(); form = confirmPage.getForms().get(1); submit = form.getInputByName("allow_access"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput sessionUsernameOrEmail = form.getInputByName("session[username_or_email]"); sessionUsernameOrEmail.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput sessionPassword = form.getInputByName("session[password]"); sessionPassword.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getElementById("allow"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput email = form.getInputByName("email"); email.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = form.getInputByName("pass"); password.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getInputByName("login"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput login = form.getInputByName("login"); login.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = form.getInputByName("password"); password.setValueAttribute("testpwdscribeup1"); final HtmlSubmitInput submit = form.getInputByName("commit"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput email = form.getInputByName("Email"); email.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput passwd = form.getInputByName("Passwd"); passwd.setValueAttribute("testpwdscribeup34"); final HtmlSubmitInput submit = form.getInputByName("signIn"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
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();
private HtmlPage submitNewRepositoryForm(HtmlPage page) throws IOException { for (HtmlForm form : page.getForms()) { for (HtmlInput mode : form.getInputsByName("mode")) { if ("new".equals(mode.getValueAttribute())) { for (HtmlInput home : form.getInputsByName("repository_home")) { home.setValueAttribute("target/repository"); for (HtmlElement submit : form.getElementsByAttribute("input", "type", "submit")) { return submit.click(); } } } } } fail(); return null; }
/** * Tests correct addListener behaviour when a project is renamed. * * @throws Exception id so. */ @LocalData @Test public void testNewProjectCreationWithReName() throws Exception { FreeStyleProject p = createGerritTriggeredJob(j, "testJob3"); HtmlForm form = j.createWebClient().getPage(p, "configure").getFormByName("config"); form.getInputByName("name").setValueAttribute("testJob33"); HtmlPage confirmPage = j.submit(form); j.submit(getFormWithAction("doRename", confirmPage.getForms())); //configRoundtrip(p); assertEquals("testJob33", p.getName()); assertNbrOfGerritEventListeners( PluginImpl.getInstance().getServer(PluginImpl.DEFAULT_SERVER_NAME)); }