当前位置: 首页>>代码示例>>Java>>正文


Java HtmlSubmitInput类代码示例

本文整理汇总了Java中com.gargoylesoftware.htmlunit.html.HtmlSubmitInput的典型用法代码示例。如果您正苦于以下问题:Java HtmlSubmitInput类的具体用法?Java HtmlSubmitInput怎么用?Java HtmlSubmitInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HtmlSubmitInput类属于com.gargoylesoftware.htmlunit.html包,在下文中一共展示了HtmlSubmitInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFormOk

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
/**
 * Retrieve a form and submit it making sure the CSRF hidden field is present
 *
 * @throws Exception an error occurs or validation fails.
 */
@Test
public void testFormOk() throws Exception {
    HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
    HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);

    // Check hidden input field
    HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
    assertTrue(input.getAttribute("type").equals("hidden"));
    assertTrue(input.getAttribute("name").equals(CSRF_PARAM));
    assertTrue(input.hasAttribute("value"));        // token

    // Submit form
    HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
    HtmlPage page2 = button.click();
    Iterator<HtmlElement> it = page2.getDocumentElement().getHtmlElementsByTagName("h1").iterator();
    assertTrue(it.next().asText().contains("CSRF Protection OK"));
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:23,代码来源:CsrfIT.java

示例2: testFormFail

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
/**
 * Retrieves a form, removes CSRF hidden field and attempts to submit. Should
 * result in a 403 error.
 *
 * @throws Exception an error occurs or validation fails.
 */
@Test
public void testFormFail() throws Exception {
    HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
    HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);

    // Remove hidden input field to cause a CSRF validation failure
    HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
    form.removeChild(input);

    // Submit form - should fail
    HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
    try {
        button.click();
        fail("CSRF validation should have failed!");
    } catch (FailingHttpStatusCodeException e) {
        // falls through
    }
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:25,代码来源:CsrfIT.java

示例3: getCallbackUrl

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
@Override
protected String getCallbackUrl(HtmlPage authorizationPage) throws Exception {

    HtmlInlineFrame frame = (HtmlInlineFrame) authorizationPage.getElementById("ptlogin_iframe");
    // log.info("------------------------###\n{}------------------------===\n", authorizationPage.asXml());
    HtmlPage loginPage = (HtmlPage) frame.getEnclosedPage();

    log.info("------------------------###\n{}------------------------===\n", loginPage.getUrl().toString());

    HtmlAnchor passwordLogin = (HtmlAnchor) loginPage.getElementById("switcher_plogin");
    passwordLogin.click();

    HtmlForm loginForm = loginPage.getFormByName("loginform");
    loginForm.getInputByName("u").setValueAttribute(USER_QQ);
    loginForm.getInputByName("p").setValueAttribute(USER_PASSWORD);
    HtmlSubmitInput button = (HtmlSubmitInput) loginPage.getElementById("login_button");
    HtmlPage page2 = button.click();
    page2 = button.click();
    log.info(
            "------------------------###\n callbackUrl : {}------------------------===\n{}[email protected]@@@\n",
            page2.getUrl().toString(), page2.asXml());
    return page2.getUrl().toString();
}
 
开发者ID:btpka3,项目名称:pac4j-oauth-tencent,代码行数:24,代码来源:TestTencentClient.java

示例4: loadPage

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
public void loadPage() {
	try {
		// Store cookies
		cookieManager = webClient.getCookieManager();
		page = webClient.getPage(URL);

		HtmlForm form = page.getFormByName("processLogonForm");
		HtmlSubmitInput button = form.getInputByName("Login");
		HtmlTextInput user = form.getInputByName("userName");
		HtmlPasswordInput pass = form.getInputByName("password");

		user.setValueAttribute(username);
		pass.setValueAttribute(password);

		page = button.click();
		if (page.asXml().contains("*  Please try again.")) {
			loginSuc = false;
			return;
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:24,代码来源:D2LHook.java

示例5: checkAdOnline

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
public static boolean checkAdOnline(String adId)
{
    try
    {
        WebClient client = Client.get();
        String urlDelete = LinkFactory.AD_DELETE_LINK_1 + adId;
        final HtmlPage deletePage1 = client.getPage(urlDelete);
        HtmlRadioButtonInput deleteRadioButton = (HtmlRadioButtonInput) deletePage1.getElementById("cmd_delete");
        deleteRadioButton.setChecked(true);

        HtmlSubmitInput continueButton = deletePage1.getElementByName("continue");
        final HtmlPage deletePage2 = continueButton.click();

        if (deletePage2.asXml().contains("dans quelques minutes") && deletePage2.asXml().contains("Vous ne pouvez pas"))
        {
            return false;
        }
    }
    catch (Exception e)
    {
        Logger.traceERROR(e);
    }

    return true;
}
 
开发者ID:philipperemy,项目名称:Leboncoin,代码行数:26,代码来源:MonitoringTask.java

示例6: webFetch

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
public void webFetch(String userInput,String pwdInput) throws Exception{
	final WebClient webClient=new WebClient();
	webClient.getOptions().setCssEnabled(false);
	webClient.getOptions().setJavaScriptEnabled(false);
	final HtmlPage page=webClient.getPage("https://account.xiaomi.com/pass/serviceLogin");
	//��ȡ��
	final HtmlForm form=(HtmlForm)page.getElementById("loginForm");
	//��ȡ�ύ�ť
	final HtmlSubmitInput button=form.getInputByValue("��¼");
	HtmlTextInput userId=form.getInputByName("user");
	HtmlPasswordInput pwd=form.getInputByName("pwd");
	userId.setText(userInput);
	pwd.setText(pwdInput);
	final HtmlPage next=button.click();
	System.out.println(next.asText());
	webClient.closeAllWindows();
}
 
开发者ID:swz887799,项目名称:Crawler_Self_Analysis,代码行数:18,代码来源:FetchUrlByHtmlUnit.java

示例7: testGetWithCorrectCredentials

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
@Test
public void testGetWithCorrectCredentials() throws Exception {
	logger.info("start get request with correct credentials");
	loginForm.getInputByName("j_username").setValueAttribute("u1");
	loginForm.getInputByName("j_password").setValueAttribute("p1");
	HtmlSubmitInput submitButton = loginForm.getInputByName("submitButton");
	HtmlPage page2 = submitButton.click();
	assertEquals("Form-based Security - Success", page2.getTitleText());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:SecureFormTestCase.java

示例8: testGetWithIncorrectCredentials

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
@Test
public void testGetWithIncorrectCredentials() throws Exception {
	logger.info("start get request with incorrect credentials");
	loginForm.getInputByName("j_username").setValueAttribute("random");
	loginForm.getInputByName("j_password").setValueAttribute("random");
	HtmlSubmitInput submitButton = loginForm.getInputByName("submitButton");
	HtmlPage page2 = submitButton.click();
	assertEquals("Form-Based Login Error Page", page2.getTitleText());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:SecureFormTestCase.java

示例9: post

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
private String post(){
	String postedUrl = null;
	String domain = Globals.paths.RemoteAdminUrl.substring(0,Globals.paths.RemoteAdminUrl.lastIndexOf("wp-admin")-1)+"/";
			
	webPageManipulation = new WebPageManipulation(connection.getStartPage());
	
	DomElement titleElement = webPageManipulation.getElementById("title");
	HtmlTextArea contentElement =(HtmlTextArea) webPageManipulation.getElementById("content");
	HtmlSubmitInput publishButton = (HtmlSubmitInput)webPageManipulation.getElementById("publish");
	
	webPageManipulation.setElement(titleElement, InputObject.getTitle());
	contentElement.setText(AdCode+"\n"+EmbedCode.replaceFirst("#", InputObject.getVideoUrl().replace("watch?v=", "/embed/"))+
			"\n"+EmbedCode.replaceFirst("#", InputObject.getVideoUrl().replace("watch?v=", "/embed/"))+"\n"+InputObject.getDescription());
	
	try {
		HtmlPage nxt = publishButton.click();
		webPageManipulation.setPage(nxt);
		
		DomElement url_posted = webPageManipulation.getElementById("editable-post-name-full");
		
		String postUrl = domain+url_posted.getTextContent();
		
		JOptionPane.showMessageDialog(null, postUrl);
		StringSelection selection = new StringSelection(postUrl);
	    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	    clipboard.setContents(selection, selection);
	} catch (IOException e) {
		//Get Default Dialog used for exceptions, & add exception
		//Show Dialog
	}
	
	return postedUrl;
}
 
开发者ID:klevinism,项目名称:Ads-Attacher,代码行数:34,代码来源:MainViewController.java

示例10: logIn

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
private void logIn()throws IOException{
    final HtmlPage page = browser.getPage("http://codeforces.com/enter");
        
    final HtmlTextInput handle = (HtmlTextInput)page.getByXPath("//input[@id='handle']").get(0);
    final HtmlPasswordInput pass = (HtmlPasswordInput)page.getByXPath("//input[@id='password']").get(0);

    final HtmlSubmitInput btn = (HtmlSubmitInput)page.getByXPath("//input[@class='submit']").get(0);

    // Change the value of the text fields
    handle.setValueAttribute(user_name);
    pass.setValueAttribute(pass_word);

    // Now submit the form by clicking the button
    btn.click();
}
 
开发者ID:AmrSaber,项目名称:XC2,代码行数:16,代码来源:Server.java

示例11: searchInBaidu

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
public void searchInBaidu() throws Exception {
	HtmlPage page = webClient.getPage("https://www.baidu.com/");  
	HtmlForm form = page.getFormByName("f");
	
	HtmlTextInput input = form.getInputByName("wd");	
	HtmlSubmitInput button = form.getInputByValue("百度一下");  
	
	input.setValueAttribute("无锡");
	HtmlPage nextPage = button.click();  
	
	//System.out.println(nextPage.asXml());
	
	// hit next page
	HtmlAnchor next = null;
	List list = nextPage.getByXPath("//a");
	for(Object obj : list) {
		if(obj instanceof HtmlAnchor) {
			HtmlAnchor ha = (HtmlAnchor)obj;
			//System.out.println(ha.getTextContent());
			if(ha.getTextContent().indexOf("百度百科") != -1) {
				next = ha;
				break;
			}
		}
	}
	
	
	System.out.println(next.asXml());
	System.out.println("--------------------------");
	HtmlPage p = next.click();
	System.out.println(p.asXml());
	
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:34,代码来源:PostDemo.java

示例12: download

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
/**
 * return the html of url
 * @param url : form data
 * @param inputs : input name -> input value
 * @return
 */
public String download(URL url, Map<String, String> inputs) {
	HtmlSubmitInput button = null;
	HtmlPage nextPage = null;
	
	try {
		HtmlPage page = webClient.getPage(url.getURLValue()); 
		for(Map.Entry<String, String> input : inputs.entrySet()) {
			String form_name = input.getKey().split("\\.")[0];
			String input_name = input.getKey().split("\\.")[1];
			
			HtmlForm form = page.getFormByName(form_name);
			if(input_name.equals("button")) {
				button = form.getInputByValue(input.getValue());
			}
			else {
				HtmlTextInput text_input = form.getInputByName(input_name);
				text_input.setValueAttribute(input.getValue());
			}
		}
		nextPage = button.click();
	} catch(IOException ioe) {
		ioe.printStackTrace();
	}
	  
	return nextPage.asXml();
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:33,代码来源:PostDownloader.java

示例13: getNextUrl

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
/**
 * 通过htmlunit来获得一些搜狗的网址。
 * @param key
 * @return
 * @throws Exception
 */
public String getNextUrl(String key){
	String page = new String();
	try {
		WebClient webClient = new WebClient();
		webClient.getOptions().setCssEnabled(false);
		webClient.getOptions().setJavaScriptEnabled(false);
		
		//去拿网页
		HtmlPage htmlPage = webClient.getPage("http://pic.sogou.com/");
		//得到表单
		HtmlForm form = htmlPage.getFormByName("searchForm");
		//得到提交按钮
		HtmlSubmitInput button = form.getInputByValue("搜狗搜索");
		//得到输入框

		HtmlTextInput textField = form.getInputByName("query");
		//输入内容
		textField.setValueAttribute(key);
		//点一下按钮
		HtmlPage nextPage = button.click();

		String str = nextPage.toString();
		page = cutString(str);
		webClient.close();
	} catch (Exception e) {
		// TODO: handle exception
	} finally{
		
	}
	System.out.println();
	return page;
	
}
 
开发者ID:anLA7856,项目名称:Crawler,代码行数:40,代码来源:CrawUrl.java

示例14: confirmRecoveryEmail

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
private HtmlPage confirmRecoveryEmail(WebClient webClient, HtmlPage htmlPage) throws IOException {
	List<HtmlForm> forms = htmlPage.getForms();
	HtmlForm challengeForm = forms.stream().filter(
			form -> "challenge".equals(form.getId()) && "/signin/challenge/kpe/2".equals(form.getActionAttribute()))
			.findFirst().get();
	HtmlInput htmlInput = challengeForm.getInputByName("email");
	htmlInput.setValueAttribute(recoveryEmail.get());
	HtmlSubmitInput signInButton = (HtmlSubmitInput) challengeForm.getInputByValue("Done");
	HtmlPage nextPage = signInButton.click();
	webClient.waitForBackgroundJavaScriptStartingBefore(WAIT_DELAY_MS);
	return nextPage;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:13,代码来源:HtmlUnitAuthorizationCodeInstalledApp.java

示例15: login

import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入依赖的package包/类
public void login(JSONObject accountProperties){
    this.logger.info("네이버에 로그인합니다: " + accountProperties.getString("username"));

    try{
        final HtmlPage loginPage = this.getPage("https://nid.naver.com/nidlogin.login?url=");
        final HtmlForm loginForm = loginPage.getFormByName("frmNIDLogin");

        final HtmlTextInput     idInput     = loginForm.getInputByName("id");
        final HtmlPasswordInput pwInput     = loginForm.getInputByName("pw");
        final HtmlSubmitInput   loginButton = (HtmlSubmitInput) loginForm.getByXPath("//fieldset/span/input").get(0);

        final String id = accountProperties.getString("username");
        final String pw = accountProperties.getString("password");

        if(id.equals("") || pw.equals("")){
            this.logger.notice("네이버 로그인 불가: 계정 정보가 설정되어 있지 않습니다");
            return;
        }

        idInput.setValueAttribute(id);
        pwInput.setValueAttribute(pw);

        Elements errors = Jsoup.parse(((HtmlPage) loginButton.click()).asXml().replaceFirst("<\\?xml version=\"1.0\" encoding=\"(.+)\"\\?>", "<!DOCTYPE html>")).select("div.error");
        if(!errors.isEmpty()) this.logger.warning("네이버 로그인 실패: " + errors.text());
    }catch(Exception e){
        this.logger.warning("네이버 로그인 실패: " + e.getClass().getName() + ": " + e.getMessage());
    }

    this.close();
}
 
开发者ID:ChalkPE,项目名称:Takoyaki,代码行数:31,代码来源:Staff.java


注:本文中的com.gargoylesoftware.htmlunit.html.HtmlSubmitInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。