• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HtmlSelect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testCreateNewDatastream

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的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: execute

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void execute(Context context)
{
	LoggerFactory.getLogger(SelectDropdown.class).debug("Executing action: " + this);
	try
	{
		HtmlSelect select = context.getXPathProcessor().getSingleElementOfType(Util.getCurrentPage(context), Util.replacePlaceholders(path, context), HtmlSelect.class);
		HtmlOption option = select.getOptionByValue(Util.replacePlaceholders(value, context));
		select.setSelectedAttribute(option, true);
	}
	catch(ElementNotFoundException e)
	{
		throw new RuntimeException("No option found for value " + value);
	}
}
 
开发者ID:sropelato,项目名称:Fetchino,代码行数:19,代码来源:SelectDropdown.java


示例3: createAndVerifyObjectWithIdFromRootPage

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
private HtmlPage createAndVerifyObjectWithIdFromRootPage(final String pid) throws IOException {
    final HtmlPage page = webClient.getPage(serverAddress);
    final HtmlForm form = (HtmlForm)page.getElementById("action_create");
    final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
    type.getOptionByValue("container").setSelected(true);

    final HtmlInput new_id = (HtmlInput)page.getElementById("new_id");
    new_id.setValueAttribute(pid);
    final HtmlButton button = form.getFirstByXPath("button");
    button.click();


    try {
        final HtmlPage page1 = webClient.getPage(serverAddress + pid);
        assertEquals("Page had wrong title!", serverAddress + pid, page1.getTitleText());
        return page1;
    } catch (final FailingHttpStatusCodeException e) {
        fail("Did not successfully retrieve created page! Got HTTP code: " + e.getStatusCode());
        return null;
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:22,代码来源:FedoraHtmlResponsesIT.java


示例4: testCreateNewDatastreamWithNoFileAttached

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的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


示例5: download

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
/**
 * Download pages from url with the specific date, and save to the directory
 *
 * @param directory Directory
 * @param queryDate Query Date
 * @param url Query URL
 */
protected void download(String directory, Date queryDate, String url) throws IOException {
  try (final WebClient webClient = getWebClient()) {
    // Get the query page
    final HtmlPage queryPage = webClient.getPage(url);

    // Get the date select list elements and the search button
    final HtmlSelect year = queryPage.getElementByName("ddlShareholdingYear");
    final HtmlSelect month = queryPage.getElementByName("ddlShareholdingMonth");
    final HtmlSelect day = queryPage.getElementByName("ddlShareholdingDay");
    final HtmlImageInput button = queryPage.getElementByName("btnSearch");

    // Change the value of the date select list
    year.setSelectedAttribute(DateFormatUtils.format(queryDate, "yyyy"), true);
    month.setSelectedAttribute(DateFormatUtils.format(queryDate, "MM"), true);
    day.setSelectedAttribute(DateFormatUtils.format(queryDate, "dd"), true);

    // Now submit the query by clicking the button and get back the result page
    final HtmlPage resultPage = (HtmlPage) button.click();
    File outputFile = new File(directory,
        DateFormatUtils.format(queryDate, "yyyyMMdd") + ".html");
    FileUtils.writeStringToFile(outputFile, resultPage.asXml(), "UTF-8");

    logger.info("Successfully downloaded HKEX web page for market {} and date {}",
        url.substring(url.length() - 2), DateFormatUtils.format(queryDate, "yyyy/MM/dd"));
  }
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:34,代码来源:Spider.java


示例6: roomBooking

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的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


示例7: removeAd

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
private static boolean removeAd(String adId)
{
    try
    {
        WebClient client = Client.get();
        String urlDelete = LinkFactory.AD_DELETE_LINK_1 + adId;
        Logger.traceINFO("URL for ad delete is : " + urlDelete);
        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("votre mot de passe tient compte des majuscules"))
        {
            Logger.traceERROR("Unknown error. Cannot remove ad with id : " + adId);
        }

        HtmlPasswordInput passwordInput = deletePage2.getElementByName("passwd");
        passwordInput.setValueAttribute(DefaultUserConf.PASSWORD);

        final HtmlSelect causeSelect = deletePage2.getElementByName("delete_reason");
        HtmlOption autreCauseSelect = causeSelect.getOptionByValue("5");
        causeSelect.setSelectedAttribute(autreCauseSelect, true);

        HtmlSubmitInput continueButton2 = deletePage2.getElementByName("continue");
        HtmlPage result = continueButton2.click();

        return result.asXml().contains("Votre annonce sera supprim") && result.asXml().contains("lors de la prochaine mise � jour");
    }
    catch (Exception e)
    {
        Logger.traceERROR(e);
        return false;
    }
}
 
开发者ID:philipperemy,项目名称:Leboncoin,代码行数:38,代码来源:AdRepublisher.java


示例8: testCreateNewNodeWithGeneratedId

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
@Test
public void testCreateNewNodeWithGeneratedId() throws IOException {

    final HtmlPage page = webClient.getPage(serverAddress);
    final HtmlForm form = (HtmlForm)page.getElementById("action_create");
    final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
    type.getOptionByValue("container").setSelected(true);
    final HtmlButton button = form.getFirstByXPath("button");
    button.click();

    final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress);
    assertTrue("Didn't see new information in page!", !page1.asText().equals(page.asText()));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:14,代码来源:FedoraHtmlResponsesIT.java


示例9: setFieldValue

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
public final static void setFieldValue(HtmlPage page, String fieldId, String fieldValue) {
    HtmlElement element = page.getHtmlElementById(fieldId);
    Assert.assertTrue("element " + fieldId + " is null, page: " + page.asText(), element != null);

    if (element instanceof HtmlTextInput) {
        HtmlTextInput textField = (HtmlTextInput) element;
        textField.setValueAttribute(fieldValue);
    } else if (element instanceof HtmlTextArea) {
        HtmlTextArea textAreaField = (HtmlTextArea) element;
        textAreaField.setText(fieldValue);
    } else if (element instanceof HtmlHiddenInput) {
        HtmlHiddenInput hiddenField = (HtmlHiddenInput) element;
        hiddenField.setValueAttribute(fieldValue);
    } else if (element instanceof HtmlSelect) {
        HtmlSelect selectField = (HtmlSelect) element;
        try {
            selectField.setSelectedAttribute(fieldValue, true);
        } catch (IllegalArgumentException e) {
            Assert.fail("select element [" + element.asText() + "] " + e.getMessage());
        }
    } else if (element instanceof HtmlCheckBoxInput) {
        HtmlCheckBoxInput checkboxField = (HtmlCheckBoxInput) element;
        if (fieldValue.equals("on")) {
            checkboxField.setChecked(true);
        } else if (fieldValue.equals("off")) {
            checkboxField.setChecked(false);
        } else {
        	Assert.assertTrue("Invalid checkbox value", false);
        }
    } else if (element instanceof HtmlFileInput) {
        HtmlFileInput fileInputField = (HtmlFileInput) element;
        fileInputField.setValueAttribute(fieldValue);
    } else if (element instanceof HtmlRadioButtonInput) {
    	HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) element;
    	if (fieldValue.equals("on")) {
    		radioButton.setChecked(true);
    	} else if (fieldValue.equals("off")) {
    		radioButton.setChecked(false);
    	}
    } else {
    	Assert.fail("Unknown control field: " + fieldId);
    }
}
 
开发者ID:kuali-mirror,项目名称:kpme,代码行数:44,代码来源:HtmlUnitUtil.java


示例10: printPlayoffScoresheets

import com.gargoylesoftware.htmlunit.html.HtmlSelect; //导入依赖的package包/类
/**
 * Visit the printable brackets for the division specified and print the
 * brackets.
 * 
 * @throws IOException
 * @throws MalformedURLException
 * @throws InterruptedException
 * @throws SAXException
 */
private static void printPlayoffScoresheets(final String division)
    throws MalformedURLException, IOException, InterruptedException, SAXException {
  final WebClient conversation = WebTestUtils.getConversation();

  final Page indexResponse = WebTestUtils.loadPage(conversation, new WebRequest(new URL(TestUtils.URL_ROOT
      + "playoff/index.jsp")));
  Assert.assertTrue(indexResponse.isHtmlPage());
  final HtmlPage indexHtml = (HtmlPage) indexResponse;

  // find form named 'printable'
  HtmlForm form = indexHtml.getFormByName("printable");
  Assert.assertNotNull("printable form not found", form);

  final String formSource = WebTestUtils.getPageSource(form.getPage());
  LOGGER.debug("Form source: "
      + formSource);

  // set division
  final HtmlSelect divisionSelect = indexHtml.getHtmlElementById("printable.division");
  final HtmlOption divisionOption = divisionSelect.getOptionByValue(division);
  divisionSelect.setSelectedAttribute(divisionOption, true);

  // click 'Display Brackets'
  final HtmlSubmitInput displayBrackets = form.getInputByValue("Display Brackets");
  final com.gargoylesoftware.htmlunit.WebRequest displayBracketsRequest = form.getWebRequest(displayBrackets);
  final Page displayResponse = WebTestUtils.loadPage(conversation, displayBracketsRequest);

  Assert.assertTrue(displayResponse.isHtmlPage());
  final HtmlPage displayHtml = (HtmlPage) displayResponse;

  // find form named 'printScoreSheets'
  form = displayHtml.getFormByName("printScoreSheets");
  Assert.assertNotNull("printScoreSheets form not found", form);

  final HtmlCheckBoxInput printCheck = form.getInputByName("print1");
  printCheck.setChecked(true);

  // click 'Print scoresheets'
  final HtmlSubmitInput print = form.getInputByValue("Print scoresheets");
  final com.gargoylesoftware.htmlunit.WebRequest printRequest = form.getWebRequest(print);
  final Page printResponse = WebTestUtils.loadPage(conversation, printRequest);

  // check that result is PDF
  Assert.assertEquals("application/pdf", printResponse.getWebResponse().getContentType());

}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:56,代码来源:FullTournamentTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PullImageResultCallback类代码示例发布时间:2022-05-21
下一篇:
Java HeightMode类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap