@Test public void submittingForm() throws Exception { final WebClient webClient = new WebClient(); // Get the first page final HtmlPage page1 = webClient.getPage("http://some_url"); // Get the form that we are dealing with and within that form, // find the submit button and the field that we want to change. final HtmlForm form = page1.getFormByName("myform"); final HtmlSubmitInput button = form.getInputByName("submitbutton"); final HtmlTextInput textField = form.getInputByName("userid"); // Change the value of the text field textField.setValueAttribute("root"); // Now submit the form by clicking the button and get back the second page. final HtmlPage page2 = button.click(); webClient.closeAllWindows(); }
/** * {@inheritDoc} Returns "Submit Query" if <tt>value</tt> attribute is not defined. */ @Override public String asText() { String text = getValueAttribute(); if (text == ATTRIBUTE_NOT_DEFINED) { text = DEFAULT_VALUE; } return text; }
@Test(groups = INTEGRATION) @SpecAssertion(section = CONVERSATION, id = "q") public void testEndTransientConversationThrowsException() throws Exception { WebClient client = new WebClient(); HtmlPage page = client.getPage(getPath("cumulus.jsf")); assert !isLongRunning(page); // try ending a transient conversation HtmlSubmitInput endConversationButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "endConversationAndSwallowException"); page = endConversationButton.click(); assert page.getBody().getTextContent().contains("Hello world!"); }
@Test(groups = { "contexts" }) @SpecAssertion(section = "6.7.4", id = "m") public void testConversationPropagatedOverRedirect() throws Exception { WebClient webClient = new WebClient(); HtmlPage storm = webClient.getPage(getPath("storm.jsf")); HtmlSubmitInput beginConversationButton = getFirstMatchingElement(storm, HtmlSubmitInput.class, "beginConversationButton"); storm = beginConversationButton.click(); HtmlTextInput stormStrength = getFirstMatchingElement(storm, HtmlTextInput.class, "stormStrength"); stormStrength.setValueAttribute(REDIRECT_STORM_STRENGTH); String stormCid = getCid(storm); HtmlSubmitInput lighteningButton = getFirstMatchingElement(storm, HtmlSubmitInput.class, "lighteningButton"); HtmlPage lightening = lighteningButton.click(); assert lightening.getWebResponse().getRequestUrl().toString().contains("lightening.jsf"); assert stormCid.equals(getCid(lightening)); stormStrength = getFirstMatchingElement(lightening, HtmlTextInput.class, "stormStrength"); assert stormStrength.getValueAttribute().equals(REDIRECT_STORM_STRENGTH); }
webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(false); // I think this speeds the thing up webClient.getOptions().setRedirectEnabled(true); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getCookieManager().setCookiesEnabled(true); HtmlPage page = webClient.getPage(url); System.out.println("1st page : "+page.asText()); HtmlForm form=(HtmlForm)page.getElementById("aspnetForm"); HtmlInput uName=(HtmlInput)form.getByXPath("//*[@id=\"ctl00_LoginControl_textUserName_text\"]").get(0); uName.setValueAttribute(name); HtmlInput acNo=(HtmlInput)form.getByXPath("//*[@id=\"ctl00_LoginControl_textCompanyAccount_text\"]").get(0); acNo.setValueAttribute(accountNo); HtmlPasswordInput password=(HtmlPasswordInput)form.getByXPath("//*[@id=\"ctl00_LoginControl_textPassword\"]").get(0); password.setValueAttribute(pass); HtmlSubmitInput button = (HtmlSubmitInput) form.getByXPath("//*[@id=\"ctl00_LoginControl_buttonLogin\"]").get(0); WebWindow window = page.getEnclosingWindow(); button.click(); while(window.getEnclosedPage() == page) {
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());
@SuppressWarnings("deprecation") private String getRefreshToken() { webClient.getOptions().setRedirectEnabled(false); authPage = webClient.getPage(url); } catch (FailingHttpStatusCodeException e) { authPage = webClient.getPage(location); done = true; } catch (FailingHttpStatusCodeException e1) { final HtmlDivision div = authPage.getFirstByXPath("//div[@role='alert']"); if (div != null) { throw new IllegalArgumentException("Error authorizing application: " + div.getTextContent()); final HtmlForm loginForm = authPage.getForms().get(0); final HtmlTextInput login = loginForm.getInputByName("session_key"); login.setText(oAuthParams.getUserName()); final HtmlPasswordInput password = loginForm.getInputByName("session_password"); password.setText(oAuthParams.getUserPassword()); final HtmlSubmitInput submitInput = (HtmlSubmitInput) loginForm.getElementsByAttribute("input", "type", "submit").get(0); final Page redirectPage = submitInput.click(); redirectQuery = redirectPage.getUrl().getQuery(); } catch (FailingHttpStatusCodeException e) {
WebClient _webClient = new WebClient( BrowserVersion.FIREFOX_17 ); _webClient.getOptions().setUseInsecureSSL( true ); _webClient.getOptions().setThrowExceptionOnScriptError( false ); _webClient.getOptions().setRedirectEnabled( true ); var page = (HtmlPage)_webClient.getPage( "https://play.google.com/apps/publish/v2/" ); HtmlInput emailElement = (HtmlTextInput)page.getElementById( "Email" ); emailElement.type( Settings.Default.Login ); HtmlInput passwordElement = (HtmlInput)page.getElementById( "Passwd" ); passwordElement.type( Settings.Default.Password ); HtmlSubmitInput signInLink = (HtmlSubmitInput)page.getElementById( "signIn" ); HtmlPage page2 = (HtmlPage)signInLink.click(); _webClient.waitForBackgroundJavaScript( 2000 ); var installsNode = ( from p in page2.getElementsByTagName( "p" ).toArray().Cast<HtmlParagraph>() let data_column = p.getAttribute( "data-column" ) where data_column != null && "INSTALLS".Equals( data_column, StringComparison.OrdinalIgnoreCase ) select p ).FirstOrDefault();
@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; }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { // disable caching webClient.getCache().setMaxSize(0); // Get the first page final HtmlPage page1 = webClient.getPage(url); final HtmlForm form = page1.getFormByName(formName); final HtmlTextInput taxCodeTextField = form.getInputByName(taxCodeTextFieldName); HtmlCheckBoxInput checkboxInput = form.getInputByName(checkboxInputName); taxCodeTextField.type(taxCode); checkboxInput.click(); //wait a little Thread.sleep(2000); //get the main page HtmlPage page2 = (HtmlPage) webClient.getTopLevelWindows().get(0).getEnclosedPage(); HtmlSubmitInput confirmButton = page2.getFormByName(formName).getInputByName(confirmButtonName); final HtmlPage page3 = confirmButton.click(); System.out.println(page3.asText()); }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { HtmlPage page = webClient.getPage("http://www.google.com"); HtmlAnchor a = page.getHtmlElementById("gb_70"); page = a.click(); HtmlForm form = (HtmlForm) page.getElementById("gaia_loginform"); HtmlTextInput email = (HtmlTextInput) page.getElementById("Email"); email.setValueAttribute(myEmailAddress); HtmlSubmitInput nextButton = page.getHtmlElementById("next"); System.out.println(nextButton.asXml()); HtmlPage newWebpage = nextButton.click(); String status = newWebpage.getWebResponse().getStatusMessage(); System.out.println(status); }
//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();
public void browse(String url) throws IOException { WebClient webClient = initWebClient(); HtmlPage htmlPage = webClient.getPage(url); //first you need login with your email and password final HtmlTextInput login = (HtmlTextInput) htmlPage.getByXPath("//input[@type='email']").get(0); final HtmlPasswordInput pass = (HtmlPasswordInput) htmlPage.getByXPath("//input[@type='password']").get(0); HtmlSubmitInput button = (HtmlSubmitInput) htmlPage.getByXPath("//input[@type='submit']").get(0); //set input login and passwd login.setText(this.login); pass.setText(this.passwd); //press submit button button.click(); //next need select account htmlPage = webClient.getPage(url); DomNodeList<HtmlElement> list = htmlPage.getElementById("account-list").getElementsByTagName("li"); String account = list.get(0).getElementsByTagName("a").get(0).getAttribute("href"); System.out.println(account); htmlPage = webClient.getPage(account); //and click submit button for approve System.out.println("Wait 10sec."); webClient.waitForBackgroundJavaScript(10000); HtmlButton submitInput = (HtmlButton) htmlPage.getElementById("submit_approve_access"); submitInput.click(); }
//Login into Tremor Games and return the client(Saves the cookies). private static WebClient tremorLogin(WebClient webClient) throws Exception { webClient.getOptions().setJavaScriptEnabled(false); HtmlPage currentPage = webClient.getPage("http://www.tremorgames.com/"); //Load page at the STRING address. HtmlInput username = currentPage.getElementByName("loginuser"); //Find element called loginuser for username username.setValueAttribute(user); //Set value for username HtmlInput password = currentPage.getElementByName("loginpassword"); //Find element called loginpassword for password password.setValueAttribute(pass); //Set value for password HtmlSubmitInput submitBtn = currentPage.getElementByName("Submit"); //Find element called Submit to submit form. currentPage = submitBtn.click(); //Click on the button. return webClient; }
//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 boolean Login(String user, String pass, String url) { try { final WebClient webClient = new WebClient(); // Get the first page final HtmlPage page1 = webClient.getPage(url); // Get the form that we are dealing with and within that form, // find the submit button and the field that we want to change. final HtmlForm form = page1.getFormByName("oauthAuthorizeForm"); final HtmlSubmitInput button = form.getInputByName("authorize"); final HtmlTextInput textField = form.getInputByName("session_login"); final HtmlPasswordInput textField2 = form.getInputByName("session_password"); // Change the value of the text field textField.setValueAttribute(user); textField2.setValueAttribute(pass); // Now submit the form by clicking the button and get back the second page. final HtmlPage page2 = button.click(); String newurl = page2.getUrl().toString(); String oauthVerifier = newurl.split("oauth_verifier=")[1].split("&")[0]; accessToken = oauthService.getOAuthAccessToken(requestToken, oauthVerifier); webClient.closeAllWindows(); logined = true; return true; } catch (Exception ex) { Logger.getLogger(ClassLinkedIn.class.getName()).log(Level.SEVERE, null, ex); } return false; }
try { String url = "https://www.linkedin.com/uas/login?goback=&trk=hb_signin"; final WebClient webClient = new WebClient(); webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); final HtmlPage loginPage = webClient.getPage(url); //Get Form By name final HtmlForm loginForm = loginPage.getFormByName("login"); final HtmlSubmitInput button = loginForm.getInputByName("signin"); final HtmlTextInput usernameTextField = loginForm.getInputByName("session_key"); final HtmlPasswordInput passwordTextField = loginForm.getInputByName("session_password"); usernameTextField.setValueAttribute(userName);//your Linkedin Username passwordTextField.setValueAttribute(password);//Your Linkedin Password final HtmlPage responsePage = button.click(); String htmlBody = responsePage.getWebResponse().getContentAsString(); System.out.println(htmlBody); } catch (Exception ex) { ex.printStackTrace(); }
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();
final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage("http://www.facebook.com"); final HtmlForm form = page1.getFormByName("login_form"); final HtmlSubmitInput button = form.getInputsByValue("Log in"); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jon@jon.com"); final HtmlTextInput textField = form.getInputByName("pass"); textField.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click();
final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage("http://www.facebook.com"); final HtmlForm form = (HtmlForm) page1.getElementById("login_form"); final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jon@jon.com"); final HtmlPasswordInput textField2 = form.getInputByName("pass"); textField2.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click();