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


Java HtmlElement.setAttribute方法代码示例

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


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

示例1: setAttribute

import com.gargoylesoftware.htmlunit.html.HtmlElement; //导入方法依赖的package包/类
public static boolean setAttribute(HtmlPage htmlPage, String xpath,
		String key, String value) {
	boolean flag = true;
	try {
		HtmlElement element = htmlPage.getFirstByXPath(xpath);
		if (element != null) {
			element.click();
			element.setAttribute(key, "");
			element.setAttribute(key, value);
		} else {
			logger.error("setAttribute element is null xpath " + xpath);
		}

	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		flag = false;
	}
	return flag;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:20,代码来源:HtmlUnitUtil.java

示例2: updateResult

import com.gargoylesoftware.htmlunit.html.HtmlElement; //导入方法依赖的package包/类
private void updateResult(TestCase testCase, WebClient webClient,
		HtmlPage page) {
	if (page != null) {
		HtmlHead head = (HtmlHead) page.getElementsByTagName("head").get(0);
		HtmlElement base = head.appendChildIfNoneExists("base");
		base.setAttribute("href", page.getUrl().toString());
		head.removeChild(base);
		head.insertBefore(base);

		testCase.setResultPageText(page.asText());
		testCase.setResultPageHTML(page.asXml());
		testCase.setResultURL(page.getUrl());
		for (Cookie cookie : webClient.getCookieManager().getCookies()) {
			JWebBrowser.setCookie(page.getUrl().toString(), cookie
					.toString());
		}

	}
	webClient.closeAllWindows();
	webClient.getCookieManager().clearCookies();
	webClient.getCache().clear();
}
 
开发者ID:vetsin,项目名称:SamlSnort,代码行数:23,代码来源:TestRunner.java

示例3: setInput

import com.gargoylesoftware.htmlunit.html.HtmlElement; //导入方法依赖的package包/类
protected void setInput(HtmlPage page, String uid, String password) {
	HtmlElement ue = (HtmlElement) page.getElementById("u");
	ue.setAttribute("value", uid);
	HtmlElement pe = (HtmlElement) page.getElementById("p");
	pe.setAttribute("value", password);
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:7,代码来源:HtmlUnitUtil.java

示例4: testSimple

import com.gargoylesoftware.htmlunit.html.HtmlElement; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void testSimple() throws Exception {
	WebClient webClient = new WebClient();
	HtmlPage page = webClient.getPage("http://" + WEB_SERVER_NAME + ":" + WEB_SERVER_PORT);
	assertTrue(page.asText().contains("JMX Domains"));

	String domain = "java.lang";
	HtmlAnchor anchor = page.getAnchorByText(domain);
	assertNotNull(anchor);
	page = anchor.click();
	assertTrue(page.asText().contains("Beans in domain " + domain));

	anchor = page.getAnchorByName("text");
	TextPage textPage = anchor.click();
	String bean = "type=Memory";
	assertTrue(textPage.getContent().contains(domain + ":" + bean));

	anchor = page.getAnchorByText(bean);
	page = anchor.click();
	assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));

	anchor = page.getAnchorByName("text");
	textPage = anchor.click();
	assertTrue(textPage.getContent().contains("Verbose"));

	HtmlForm form = page.getFormByName("Verbose");
	assertNotNull(form);
	HtmlInput input = form.getInputByName("val");
	assertEquals("false", input.getValueAttribute());
	assertNotNull(input);
	input.setValueAttribute("true");
	HtmlElement button = (HtmlElement) page.createElement("button");
	button.setAttribute("type", "submit");
	// append the button to the form to simulate
	form.appendChild(button);
	// submit the form
	page = button.click();
	assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));

	form = page.getFormByName("Verbose");
	assertNotNull(form);
	input = form.getInputByName("val");
	assertEquals("true", input.getValueAttribute());

	String operation = "gc";
	form = page.getFormByName(operation);
	assertNotNull(form);
	input = form.getInputByValue(operation);
	page = input.click();

	assertTrue(page.asText().contains("Invoking Operation " + operation));
	assertTrue(page.asText().contains(operation + " method successfully invoked."));

	anchor = page.getAnchorByName("text");
	assertNotNull(anchor);
	textPage = anchor.click();
	assertEquals(operation + " method successfully invoked.\n", textPage.getContent());
}
 
开发者ID:j256,项目名称:simplejmx,代码行数:59,代码来源:JmxWebHandlerTest.java


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