Refine search
@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} */ @Override public String getText() { return getValueAttribute(); }
@Override void typeDone(final String newValue, final int newCursorPosition) { setAttribute("value", newValue); setSelectionStart(newCursorPosition); setSelectionEnd(newCursorPosition); } };
/** * {@inheritDoc} */ @Override public void setDefaultValue(final String defaultValue) { final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); }
@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; }
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; }
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 { 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(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 }
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); }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { // Get the first page final HtmlPage page1 = webClient.getPage("http://www.homedepot.ca"); // 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("search_terms_form"); final HtmlElement button = form.getFirstByXPath("//button[@class='search-button']"); final HtmlTextInput textField = form.getInputByName("q"); // Change the value of the text field textField.setValueAttribute("drill"); // Now submit the form by clicking the button button.click(); System.out.println(page1.getTitleText()); }
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();
//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.getFormByName("loginform"); final HtmlTextInput login = form.getInputByName("log"); login.setValueAttribute("testscribeup"); final HtmlPasswordInput passwd = form.getInputByName("pwd"); passwd.setValueAttribute("testpwdscribeup"); HtmlElement button = authorizationPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // HtmlButton button = form.getButtonByName("wp-submit"); final HtmlPage confirmPage = button.click(); form = confirmPage.getFormByName("loginform"); button = confirmPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // button = form.getButtonByName("wp-submit"); final HtmlPage callbackPage = button.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
System.out.println(loginPage.getTitleText()); List<HtmlForm> forms = loginPage.getForms(); HtmlForm loginForm = forms.get(0); HtmlTextInput username = loginForm.getInputByName("Email"); HtmlPasswordInput password = loginForm.getInputByName("Passwd"); HtmlInput submit = loginForm.getInputByName("signIn"); username.setValueAttribute("username"); password.setValueAttribute("password"); HtmlPage homePage = submit.click();. Thread.sleep(10 * 1000); HtmlPage homePageFrame = (HtmlPage) homePage.getFrameByName("orkutFrame").getEnclosedPage(); HtmlPage communitiesTestPage = (HtmlPage) webClient.openWindow(new URL("http://www.orkut.co.in/Main#Community?cmm=1"), "CommunitiesWindow").getEnclosedPage(); }catch(java.security.GeneralSecurityException e) {
/** * Sets the text contained within the range. * @param text the text contained within the range */ public void jsxSet_text(final String text) { collapsed_ = false; final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); final String oldValue = input.getValueAttribute(); input.setValueAttribute(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } } }
@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); }
HtmlForm form = (HtmlForm) page.getByXPath("/html/body/form").get(0); HtmlTextInput name = form.getInputByName("name"); name.setValueAttribute(NAME); HtmlTextInput quest = form.getInputByName("quest"); quest.setValueAttribute(QUESTION); HtmlSelect color = form.getOneHtmlElementByAttribute("select", "name", "color"); List<HtmlOption> options = color.getOptions(); for(HtmlOption op:options){ HtmlPage page2 = submit.click(); String color2 = ((HtmlItalic)page2.getByXPath("//dd[1]/i").get(0)).getTextContent(); String name2 = ((HtmlItalic)page2.getByXPath("//dd[2]/i").get(0)).getTextContent(); String quest2 = ((HtmlItalic)page2.getByXPath("//dd[3]/i").get(0)).getTextContent(); String swallow2 = ((HtmlItalic)page2.getByXPath("//dd[4]/i").get(0)).getTextContent();
private void Login() throws FailingHttpStatusCodeException, MalformedURLException, IOException { WebClient client = new WebClient(); client.setJavaScriptEnabled(false); HtmlPage page = client.getPage("http://svergja.com/forum/"); HtmlForm form = (HtmlForm) page.getElementById("navbar_loginform"); HtmlTextInput username = (HtmlTextInput) page.getElementById("navbar_username"); username.setValueAttribute("stackoverflow"); HtmlPasswordInput password = (HtmlPasswordInput) page.getElementById("navbar_password"); password.setValueAttribute("stackit123"); HtmlSubmitInput button = form.getInputByValue("Log in"); page = button.click(); List<HtmlAnchor> anchorList = page.getAnchors(); for (HtmlAnchor htmlAnchor : anchorList) { if(htmlAnchor.getAttribute("href").contains("member.php?")) { page = htmlAnchor.click(); } } HtmlSpan span = (HtmlSpan) page.getElementById("userinfo"); DomNodeList<DomNode> nodeList = span.getChildNodes(); for (DomNode domNode : nodeList) { NamedNodeMap map = domNode.getAttributes(); Node node = map.getNamedItem("class"); if(node != null && node.getNodeValue() != null && node.getNodeValue().equals("usertitle")) { System.out.println("The usergroup is "+domNode.getTextContent()); } } }