本文整理汇总了Java中com.gargoylesoftware.htmlunit.html.DomNodeList类的典型用法代码示例。如果您正苦于以下问题:Java DomNodeList类的具体用法?Java DomNodeList怎么用?Java DomNodeList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DomNodeList类属于com.gargoylesoftware.htmlunit.html包,在下文中一共展示了DomNodeList类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: roomBooking
import com.gargoylesoftware.htmlunit.html.DomNodeList; //导入依赖的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 );
}
}
示例2: testEntries
import com.gargoylesoftware.htmlunit.html.DomNodeList; //导入依赖的package包/类
/**
* Tests that all menu entries point to an existing page.
*
* @throws IOException In case of I/O error.
*/
@Test
public void testEntries() throws IOException {
HtmlPage page = getWebClient().getPage("http://localhost/");
HtmlNav menu = page.<HtmlNav> getHtmlElementById("main-menu");
DomNodeList<HtmlElement> anchors = menu.getElementsByTagName("a");
for (HtmlElement anchor : anchors) {
LOGGER.debug("Testing {}", ((HtmlAnchor) anchor).getHrefAttribute());
HtmlPage newPage = (HtmlPage) anchor.click();
assertThat(newPage.getWebResponse().getStatusCode()).isEqualTo(HttpStatus.OK.value());
}
}
示例3: getNextPageUrl
import com.gargoylesoftware.htmlunit.html.DomNodeList; //导入依赖的package包/类
/**
* 根据提供的HtmlPage寻找上一页的URL
* @param page
* @return
*/
private String getNextPageUrl(HtmlPage page) {
DomNodeList<DomElement> thElement = page.getElementsByTagName("th");
for (DomElement element: thElement) {
if ("foot".equals(element.getAttribute("class"))) {
DomNodeList<HtmlElement> aElement = element.getElementsByTagName("a");
for (HtmlElement tempElement: aElement) {
if ("上页".equals(tempElement.getTextContent())) {
return tempElement.getAttribute("href");
}
}
}
}
return null;
}
示例4: main
import com.gargoylesoftware.htmlunit.html.DomNodeList; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://www.gnu.org/home.es.html");
DomNodeList<DomElement> nodeList = page.getElementsByTagName("a");
for (DomElement element : nodeList){
System.out.println(element.getTextContent()+ " -> " +element.getAttribute("href"));
}
}
示例5: getElementsByTagName
import com.gargoylesoftware.htmlunit.html.DomNodeList; //导入依赖的package包/类
public DomNodeList<DomElement> getElementsByTagName(String tagName){
return this.Page.getElementsByTagName(tagName);
}