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


Java HtmlPage.getElementsByTagName方法代码示例

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


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

示例1: roomBooking

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

示例2: testView1

import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
@Test
public void testView1() throws Exception {
    final HtmlPage page = webClient.getPage(webUrl + "resources/person");
    List<DomElement> div = page.getElementsByTagName("div");
    assertEquals(3, div.size());
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:7,代码来源:HandlebarsIT.java


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