當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlForm.getInputByName方法代碼示例

本文整理匯總了Java中com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlForm.getInputByName方法的具體用法?Java HtmlForm.getInputByName怎麽用?Java HtmlForm.getInputByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.gargoylesoftware.htmlunit.html.HtmlForm的用法示例。


在下文中一共展示了HtmlForm.getInputByName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateNewDatastream

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Test
@Ignore("The htmlunit web client can't handle the HTML5 file API")
public void testCreateNewDatastream() throws IOException {

    final String pid = randomUUID().toString();

    // can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
    final HtmlPage page = webClient.getPage(serverAddress);
    final HtmlForm form = (HtmlForm)page.getElementById("action_create");

    final HtmlInput slug = form.getInputByName("slug");
    slug.setValueAttribute(pid);

    final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
    type.getOptionByValue("binary").setSelected(true);

    final HtmlFileInput fileInput = (HtmlFileInput)page.getElementById("datastream_payload");
    fileInput.setData("abcdef".getBytes());
    fileInput.setContentType("application/pdf");

    final HtmlButton button = form.getFirstByXPath("button");
    button.click();

    final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress + pid);
    assertEquals(serverAddress + pid, page1.getTitleText());
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:27,代碼來源:FedoraHtmlResponsesIT.java

示例2: mockLogin

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
public String mockLogin(URL url, String username, String password) {
	try {
		HtmlPage page1 = webClient.getPage(url.getURLValue());  
		// find the login form
        HtmlForm form = page1.getForms().get(0);  
        
        // fill in the input
        HtmlInput hi = form.getInputByName("commit");
        HtmlTextInput textField = form.getInputByName("login");  
        HtmlPasswordInput pass = form.getInputByName("password");  
        
        textField.click();
        textField.setValueAttribute(username);  
        pass.click();
        pass.setValueAttribute(password);  
      
        // push the button
        HtmlPage page2 = hi.click();  
        return page2.asXml();

	} catch(IOException ioe)  {
		ioe.printStackTrace();
		return null;
	}
}
 
開發者ID:knshen,項目名稱:JSearcher,代碼行數:26,代碼來源:GithubLoginSimulator.java

示例3: loadPage

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例4: testInvalidSessionIdHelper

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
private void testInvalidSessionIdHelper(final String button, final String name, final String failMsg, final boolean fakeAppendedSessionId) throws IOException, JaxenException {
  HtmlPage editPage = clickEditLink(getWikiPage(name));
  final HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
  final HtmlInput sessionId = form.getInputByName("sessionId");
  sessionId.setValueAttribute(FAKE_SESSION_ID);
  if (fakeAppendedSessionId) {
    form.setActionAttribute(name + ";jsessionid=" + FAKE_SESSION_ID);
  }
  final HtmlTextArea content = form.getTextAreaByName("content");
  final String expectedContent = "http://www.example.com";
  content.setText(expectedContent);

  editPage = (HtmlPage) form.getButtonByName(button).click();

  try {
    getAnchorByHrefContains(editPage, expectedContent);
    fail(failMsg);
  }
  catch (NoSuchElementException e) {
  }
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:22,代碼來源:TestEditing.java

示例5: webFetch

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例6: testCreateNewDatastreamWithNoFileAttached

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Test
public void testCreateNewDatastreamWithNoFileAttached() throws IOException {

    final String pid = randomUUID().toString();

    // can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
    final HtmlPage page = webClient.getPage(serverAddress);
    final HtmlForm form = (HtmlForm)page.getElementById("action_create");

    final HtmlInput slug = form.getInputByName("slug");
    slug.setValueAttribute(pid);

    final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
    type.getOptionByValue("binary").setSelected(true);

    final HtmlButton button = form.getFirstByXPath("button");
    button.click();

    javascriptlessWebClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    final int status = javascriptlessWebClient.getPage(serverAddress + pid).getWebResponse().getStatusCode();
    assertEquals(NOT_FOUND.getStatusCode(), status);
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:23,代碼來源:FedoraHtmlResponsesIT.java

示例7: roomBooking

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
public void roomBooking( User user, Meeting meeting ) throws Exception
{

    List< String > errorMessages = new ArrayList< String >();
    HtmlPage page = navigateToPage( user, BOOKING, true );
    logger.debug( "Page loaded" );

    HtmlForm form = page.getForms().get( 0 );
    HtmlButton button = form.getFirstByXPath( "//*[@id=\"Submit\"]" );

    HtmlSelect select = (HtmlSelect)page.getElementById( "ConferenceRooms" );
    HtmlOption option = select.getOptionByText( meeting.getRoom() );
    select.setSelectedAttribute( option, true );

    Date date = meeting.getDate();
    if( date != null )
    {
        HtmlTextInput startDate = form.getFirstByXPath( ".//*[@id='StartDate']" );
        DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy" );
        startDate.setAttribute( "value", formatter.format( date ) );
    }

    HtmlInput inputStartTime = form.getInputByName( "StartTime" );
    inputStartTime.setValueAttribute( meeting.getFromTime() );

    HtmlInput inputEndTime = form.getInputByName( "EndTime" );
    inputEndTime.setValueAttribute( meeting.getToTime() );

    HtmlInput inputReason = form.getInputByName( "Title" );
    inputReason.type( meeting.getReason() );

    List< String > attendeesList = meeting.getAttendees();
    if( attendeesList != null && attendeesList.size() > 0 )
    {
        HtmlSelect attendees = (HtmlSelect)page.getElementById( "AttendeesIds" );
        for( String participant : attendeesList )
        {
            attendees.getOptionByText( participant ).setSelected( true );
        }
    }
    logger.debug( "Page filled, clicking button" );
    HtmlPage nextPage = button.click();
    
    String pageUrl = new StringBuilder( "http://" ).append( WEBSITE ).append( SHOW_MY_BOOKINGS ).toString();
    if( !nextPage.getBaseURI().equals( pageUrl ) )
    {
        errorMessages.add( "Room already booked" );
        logger.error( errorMessages );
        throw new InvalidInputException( errorMessages );
    }

    // Error check
    DomNodeList< DomElement > list = page.getElementsByTagName( "span" );
    for( DomElement domElement : list )
    {
        if( domElement.getAttribute( "class" ).contains( "field-validation-error" ) )
        {
            errorMessages.add( domElement.getTextContent() );
        }
    }

    if( errorMessages.size() > 0 )
    {
        logger.error( errorMessages );
        throw new InvalidInputException( errorMessages );
    }
}
 
開發者ID:Vedang18,項目名稱:ProBOT,代碼行數:68,代碼來源:Bookie.java

示例8: searchInBaidu

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例9: download

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例10: getNextUrl

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例11: confirmRecoveryEmail

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例12: login

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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

示例13: setup

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Before
    public void setup() throws IOException {
        String hostProperty = System.getProperty("jonas.host");
        if (hostProperty != null) {
            this.config.setHost(hostProperty);
        }

        String portProperty = System.getProperty("webcontainer.port");
        if (portProperty != null) {
            this.config.setPort(Long.parseLong(portProperty));
        }

        this.urlString = "http://" + config.getHost() + ":" + config.getPort()+ "/paas-portal/";
        log.debug("setUp urlString=" + urlString);
        final HtmlPage page = webClient.getPage(urlString);
        WebAssert.assertTitleEquals(page, "GASSI - El Paaso login");

        final HtmlForm form = page.getFormByName("loginform");
        final HtmlSubmitInput button = form.getInputByName("submit");
        final HtmlTextInput login = form.getInputByName("login");
        final HtmlPasswordInput password = form.getInputByName("password");
        login.setText("tescalle");
        password.setText("tescalle");
        home = button.click();
        // TODO : uncomment when dbaas deletion will be working on env deletion
//        home = webClient.getPage("http://" + host + ":" + port + "/paas-portal/app/scalability/setup");
    }
 
開發者ID:orange-cloudfoundry,項目名稱:elpaaso-core,代碼行數:28,代碼來源:BaseHmlUnit.java

示例14: testPreview

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
public void testPreview() throws Exception {
  String name = uniqueWikiPageName("PreviewPageTest");
  HtmlPage editPage = clickEditLink(getWikiPage(name));
  HtmlForm form = editPage.getFormByName(ID_EDIT_FORM);
  HtmlInput minorEdit = form.getInputByName("minorEdit");
  assertFalse(minorEdit.isChecked());
  minorEdit.setChecked(true);
  HtmlInput description = form.getInputByName("description");
  String expectedDescription = "My test change";
  description.setValueAttribute(expectedDescription);
  HtmlTextArea content = form.getTextAreaByName("content");
  String expectedContent = "http://www.example.com";
  content.setText(expectedContent);

  // Now if we preview we should get the previewed text rendered, and in
  // the edit area.  The other options should be preserved too.
  editPage = (HtmlPage) form.getButtonByName("preview").click();
  form = editPage.getFormByName(ID_EDIT_FORM);
  minorEdit = form.getInputByName("minorEdit");
  description = form.getInputByName("description");
  content = form.getTextAreaByName("content");
  assertEquals(expectedDescription, description.getValueAttribute());
  assertTrue(minorEdit.isChecked());
  assertEquals(expectedContent + NEWLINE_TEXTAREA, content.getText());
  // This checks for the rendering...
  assertNotNull(editPage.getAnchorByHref(expectedContent));
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:28,代碼來源:TestEditing.java

示例15: renamePage

import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
protected HtmlPage renamePage(final String pageFrom, final String pageTo) throws IOException {
  HtmlPage page = getWikiPage(pageFrom);
  HtmlAnchor renameAnchor = page.getAnchorByName("rename");
  page = (HtmlPage) renameAnchor.click();
  final HtmlForm form = page.getFormByName("renameForm");
  final HtmlInput input = form.getInputByName("toPage");
  input.setValueAttribute(pageTo);
  page = (HtmlPage) (form.getButtonByName("rename")).click();
  assertEquals(1, page.getByXPath("id('wiki-rendering')").size());
  return page;
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:12,代碼來源:WebTestSupport.java


注:本文中的com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。