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


Java DomElement类代码示例

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


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

示例1: testParseGoogle

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
@Test
public void testParseGoogle() {
	String link = "https://www.google.com/finance?q=NYSE%3ALCI&fstype=ii";
	String datesText = "In Millions of USD (except for per share items)";
	Document d;
	try (WebClient wc = new WebClient()){
		HtmlPage page = wc.getPage(link);
		List<DomElement> balanceSheet = page.getElementsByIdAndOrName("Balance Sheet");
		HtmlElement b = page.getBody();
		
		d = Jsoup.connect(link).get();
		Element body = d.body();
		Elements datesRefElts = body.getElementsMatchingOwnText(datesText);
		Element elementById = body.getElementById("fs-table");
		
		if (datesRefElts.size() > 0) {

		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:charcode,项目名称:StockScreener,代码行数:24,代码来源:GoogleFinanceParse.java

示例2: techFormTest

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
@Ignore
@Test
// TODO: This method of testing does not work for angular, need to find an alternative method of testing
public void techFormTest() {
    final WebClient webClient = new WebClient(BrowserVersion.CHROME);
    HtmlPage page;
    String port = System.getProperty("liberty.test.port");
    try {
        page = webClient.getPage("http://localhost:" + port + "/start/");
        DomElement techForm = page.getElementById("techTable");
        DomElement formBody = techForm.getFirstElementChild();
        int count = formBody.getChildElementCount();
        // We expect there to be more than one child element, otherwise the 
        // javascript has not created the tech table properly.
        assertTrue("Expected more than one element in the tech table, instead found " + count, count > 1);
    } catch (Exception e){
        org.junit.Assert.fail("Caught exception: " + e.getCause().toString());
    } finally {
        webClient.close();
    }
}
 
开发者ID:WASdev,项目名称:tool.accelerate.core,代码行数:22,代码来源:PageFunctionTest.java

示例3: fillPageContent

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
/**
 * 根据传递进来的PkuBean对象里面的URL<br/>
 * 访问对应的页面,拿到帖子的具体信息
 * @param PkuBean
 * @return
 */
private PkuBean fillPageContent(PkuBean bean) {
	String url = bean.getUrl();
	url = PREFIX_URL + url;
	HtmlPage page = fetch.fetchPage(url);
	List<DomElement> tableElement = page.getElementsByTagName("table");
	DomElement targetElement = null;
	for (DomElement element: tableElement) {
		if ("doc".equals(element.getAttribute("class"))) {
			targetElement = element;
			break;
		}
	}
	bean.setContent(targetElement.asXml());
	return bean;
}
 
开发者ID:xianlubird,项目名称:PkuIntern,代码行数:22,代码来源:PkuFetch.java

示例4: getCourses

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
public List<CourseObject> getCourses() {
	List<CourseObject> courses = new ArrayList<>();
	try {
		// Wait for javascript to load
		JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager();
		while (manager.getJobCount() > 5) {}

		for (Object object : page.getByXPath("//a[@class='vui-link d2l-link d2l-left']")) {
			DomElement de = (DomElement) object;
			courses.add(new CourseObject(de.getAttribute("href").replace("/d2l/lp/ouHome/home.d2l?ou=", ""), de.getAttribute("title").replace("Enter ", "")));
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	return courses;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:18,代码来源:D2LHook.java

示例5: getLocker

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
public List<LockerObject> getLocker(boolean previewLink) {
	List<LockerObject> list = new ArrayList<>();
	try {
		WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
		webClient.setCookieManager(cookieManager);

		HtmlPage page = webClient.getPage("https://pdsb.elearningontario.ca/d2l/lms/locker/locker.d2l?ou=8340");

		for (Object object : page.getByXPath("//a")) {
			DomElement de = (DomElement) object;
			if (de.asXml().toString().contains("/d2l/common/viewFile.d2lfile/Database/")) {
				if (!previewLink) {
					list.add(new LockerObject(de.getAttribute("title").replace("Open ", ""),  "https://pdsb.elearningontario.ca" + de.getAttribute("href").replace("&display=1", "")));
				} else {
					list.add(new LockerObject(de.getAttribute("title").replace("Open ", ""),  "https://pdsb.elearningontario.ca" + de.getAttribute("href")));

				}
			}
		}

		webClient.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return list;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:27,代码来源:D2LHook.java

示例6: getNotifications

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
public List<NotificationObject> getNotifications(String ID) throws InvaildCourseException {
	List<NotificationObject> list = new ArrayList<>();
	try {
		WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
		webClient.setCookieManager(cookieManager);

		UnexpectedPage page = webClient.getPage("https://pdsb.elearningontario.ca/d2l/MiniBar/" + ID + "/ActivityFeed/GetAlerts?Category=1&_d2l_prc%24headingLevel=2&_d2l_prc%24scope=&_d2l_prc%24hasActiveForm=false&isXhr=true&requestId=2");
		NotificationFormater notificationFormater = new NotificationFormater(page.getWebResponse().getContentAsString());
		
		webClient.close();
		
		for (Object object: notificationFormater.getNotifications()) {
			DomElement de = (DomElement) object;
			String[] split = de.asText().split("\\n");
			
			list.add(new NotificationObject(split[0].trim(), split[1].trim(), split[2].trim()));
		}
	} catch (Exception e) {
		throw new InvaildCourseException("Invaild Course ID");
	}
	
	return list;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:24,代码来源:D2LHook.java

示例7: getChannelIdsOnChannelsHtml

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
/**
 * Returns a list of channel IDs that are displayed on the channels.html page for the bounce proxy.
 * 
 * @param webClient
 * @param url
 * @return
 * @throws Exception
 */
public static List<String> getChannelIdsOnChannelsHtml(WebClient webClient, String url) throws Exception {

    HtmlPage page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(2000);

    DomElement channelsTable = page.getElementById("channels");

    List<String> channelIds = new LinkedList<String>();
    for (DomElement channelsTableRows : channelsTable.getChildElements()) {
        if (channelsTableRows.getTagName().equals("tbody")) {

            for (DomElement channelRows : channelsTableRows.getChildElements()) {

                String channelId = channelRows.getChildNodes().get(0).getTextContent();
                if (isProperChannelId(channelId)) {
                    channelIds.add(channelId);
                }
            }
        }
    }
    return channelIds;
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:31,代码来源:ChannelServiceTestUtils.java

示例8: shouldNotSeeMigrationButton

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
@Test
public void shouldNotSeeMigrationButton() throws IOException, SAXException {
    JenkinsRule.WebClient webClient = jenkinsRule.createWebClient();
    DomElement configureSection = webClient.goTo("configure").getElementsByName("AwsCodeCommitTriggerPlugin").get(0);
    List<?> buttons = configureSection.getByXPath("//button[contains(.,'Migration')]");
    Assertions.assertThat(buttons).isEmpty();
}
 
开发者ID:riboseinc,项目名称:aws-codecommit-trigger-plugin,代码行数:8,代码来源:MigrateTo2xJenkinsIT.java

示例9: roomBooking

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

示例10: post

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

示例11: getAnchor

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
private HtmlAnchor getAnchor(DomElement li) {
	for (DomElement element : li.getChildElements()) {
		HtmlAnchor anchor;
		if (element instanceof HtmlAnchor)
			return (HtmlAnchor) element;
		else if ((anchor = getAnchor(element)) != null)
			return anchor;
	}
	return null;
}
 
开发者ID:GregSkl,项目名称:WikiShort,代码行数:11,代码来源:CustomThread.java

示例12: getNextPageUrl

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的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;
}
 
开发者ID:xianlubird,项目名称:PkuIntern,代码行数:20,代码来源:PkuFetch.java

示例13: getCourseContent

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
public List<ContentObject> getCourseContent(String ID) throws InvaildCourseException {
	List<ContentObject> list = new ArrayList<>();
	try {
		WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
		webClient.setCookieManager(cookieManager);

		HtmlPage page = webClient.getPage("https://pdsb.elearningontario.ca/d2l/le/content/" + ID + "/Home");

		for (Object object : page.getByXPath("//li[@class='d2l-le-TreeAccordionItem d2l-le-TreeAccordionItem-Root']")) {
			DomElement de = (DomElement) object;
			if (de.getId().contains("D2L_LE_Content_TreeBrowser_D2L.LE.Content.ContentObject.ModuleCO-")) {
				String[] split = de.asText().split("\\n");
				List<String> ob = new ArrayList<>();

				for (int i = 1; i < split.length; i++) {
					ob.add(split[i]);
				}

				list.add(new ContentObject(split[0], ob));
			}
		}
		webClient.close();
	} catch (Exception e) {
		throw new InvaildCourseException("Invaild Course ID");
	}
	return list;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:28,代码来源:D2LHook.java

示例14: getInputs

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
/**
 * Returns all input elements on a given HtmlPage.
 * 
 * @param page
 *            The page to get inputs from.
 * @return All inputs from page.
 */
public static ArrayList<DomElement> getInputs(HtmlPage page) {

	List<DomElement> elems = page.getElementsByTagName("input");

	ArrayList<DomElement> inputs = new ArrayList<DomElement>();
	for (DomElement e : elems) {
		inputs.add(e);
	}

	return inputs;
}
 
开发者ID:gemarcano,项目名称:SWEN-Fuzzer,代码行数:19,代码来源:InputDiscovery.java

示例15: _getElements

import com.gargoylesoftware.htmlunit.html.DomElement; //导入依赖的package包/类
/**
 * Recursively get all the child elements of a DOM element
 * 
 * @param e
 *            element to get children of
 * @return all child elements of e
 */
private static ArrayList<DomElement> _getElements(DomElement e) {
	ArrayList<DomElement> elements = new ArrayList<DomElement>();
	Iterable<DomElement> children = e.getChildElements();
	for (DomElement child : children) {
		elements.add(child);
		elements.addAll(_getElements(child));
	}
	return elements;
}
 
开发者ID:gemarcano,项目名称:SWEN-Fuzzer,代码行数:17,代码来源:InputDiscovery.java


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