Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlElement#getAttribute()
The following examples show how to use
com.gargoylesoftware.htmlunit.html.HtmlElement#getAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TapestrySecurityIntegrationTest.java From tapestry-security with Apache License 2.0 | 6 votes |
@Test(groups = {"notLoggedIn"}) public void testUserFilterWithAjaxDeny() throws Exception { clickOnBasePage("tynamoLoginLink"); loginAction(); clickOnBasePage("contributed"); // now go log out in a different "window" HtmlPage indexPage = webClient.getPage(BASEURI); indexPage.getHtmlElementById("tynamoLogoutLink").click(); // Clicking on this link should make an ajax request, but HTMLUnit doesn't like it and sends a non-ajax request HtmlElement ajaxLink = (HtmlElement) page.getElementById("ajaxLink"); URL ajaxUrl = new URL(APP_HOST_PORT + ajaxLink.getAttribute("href")); WebRequest ajaxRequest = new WebRequest(ajaxUrl); ajaxRequest.setAdditionalHeader("X-Requested-With", "XMLHttpRequest"); Page jsonLoginResponse = webClient.getPage(ajaxRequest); String ajaxLoginResp = jsonLoginResponse.getWebResponse().getContentAsString(); JSONObject jsonResp = new JSONObject(ajaxLoginResp); String ajaxRedirectUrl = jsonResp.getString("redirectURL"); assertTrue(ajaxRedirectUrl.startsWith(APP_CONTEXT + "security/login"), "The ajax redirect response '" + ajaxRedirectUrl + "' did not start with '" + APP_CONTEXT + "security/login'"); page = webClient.getPage(APP_HOST_PORT + ajaxRedirectUrl); assertLoginPage(); }
Example 2
Source File: DOMStringMap.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { final HtmlElement e = (HtmlElement) getDomNodeOrNull(); if (e != null) { final String value = e.getAttribute("data-" + decamelize(name)); if (value != DomElement.ATTRIBUTE_NOT_DEFINED) { return value; } } return NOT_FOUND; }
Example 3
Source File: DOMStringMap.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { final HtmlElement e = (HtmlElement) getDomNodeOrNull(); if (e != null) { final String value = e.getAttribute("data-" + decamelize(name)); if (value != DomElement.ATTRIBUTE_NOT_DEFINED) { return value; } } return NOT_FOUND; }
Example 4
Source File: LockableResourceRootActionSEC1361Test.java From lockable-resources-plugin with MIT License | 4 votes |
private void checkXssWithResourceName(String resourceName) throws Exception { LockableResourcesManager.get().createResource(resourceName); j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); j.jenkins.setAuthorizationStrategy(new FullControlOnceLoggedInAuthorizationStrategy()); JenkinsRule.WebClient wc = j.createWebClient(); wc.login("user"); final AtomicReference<String> lastAlertReceived = new AtomicReference<>(); wc.setAlertHandler( new AlertHandler() { @Override public void handleAlert(Page page, String s) { lastAlertReceived.set(s); } }); HtmlPage htmlPage = wc.goTo("lockable-resources"); assertThat(lastAlertReceived.get(), nullValue()); // currently only one button but perhaps in future version of the core/plugin, // other buttons will be added to the layout List<HtmlElement> allButtons = htmlPage.getDocumentElement().getElementsByTagName("button"); assertThat(allButtons.size(), greaterThanOrEqualTo(1)); HtmlElement reserveButton = null; for (HtmlElement b : allButtons) { String onClick = b.getAttribute("onClick"); if (onClick != null && onClick.contains("reserve")) { reserveButton = b; } } assertThat(reserveButton, not(nullValue())); try { HtmlElementUtil.click(reserveButton); } catch (FailingHttpStatusCodeException e) { // only happen if we have a XSS, but it's managed using the AlertHandler to ensure it's a XSS // and not just an invalid page } assertThat(lastAlertReceived.get(), nullValue()); }