本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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());
}