Refine search
/** * <p>Click the specified hyperlink, and retrieve the subsequent page, * saving a reference so that other utility methods may be used to * retrieve information from it.</p> * * @param anchor Anchor component to click * * @exception IOException if an input/output error occurs */ protected HtmlPage link(HtmlAnchor anchor) throws IOException { HtmlPage page = (HtmlPage) anchor.click(); this.page = page; return page; }
/** * Returns this link's current URL. * @return this link's current URL * @throws MalformedURLException if an error occurs */ private URL getUrl() throws MalformedURLException { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); return ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(anchor.getHrefAttribute()); }
/** * Sets the focus to this element. */ @Override public void focus() { final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie(); final String hrefAttr = anchor.getHrefAttribute(); if (hrefAttr != DomElement.ATTRIBUTE_NOT_DEFINED) { anchor.focus(); } }
final String href = getHrefAttribute() + hrefSuffix; if (LOG.isDebugEnabled()) { final String w = defaultPage.getEnclosingWindow().getName(); return defaultPage; final HtmlPage page = (HtmlPage) getPage(); if (TextUtil.startsWithIgnoreCase(href, JAVASCRIPT_PREFIX)) { return page.executeJavaScriptIfPossible(href, "javascript url", getStartLineNumber()).getNewPage(); final URL url = page.getFullyQualifiedUrl(href); final WebRequestSettings wrs = new WebRequestSettings(url); wrs.setAdditionalHeader("Referer", page.getWebResponse().getRequestSettings().getUrl().toExternalForm()); if (LOG.isDebugEnabled()) { LOG.debug( return page.getWebClient().getPage( page.getEnclosingWindow(), page.getResolvedTarget(getTargetAttribute()), wrs);
final String href = (getHrefAttribute() + hrefSuffix).trim(); if (LOG.isDebugEnabled()) { final String w = getPage().getEnclosingWindow().getName(); LOG.debug("do click action in window '" + w + "', using href '" + href + "'"); if (ATTRIBUTE_NOT_DEFINED == getHrefAttribute()) { return; HtmlPage page = (HtmlPage) getPage(); if (StringUtils.startsWithIgnoreCase(href, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { final StringBuilder builder = new StringBuilder(href.length()); if (hasFeature(ANCHOR_IGNORE_TARGET_FOR_JS_HREF) && !shiftKey && !ctrlKey) { page.executeJavaScript(builder.toString(), "javascript url", getStartLineNumber()); target = page.getResolvedTarget(getTargetAttribute()); page.executeJavaScript(builder.toString(), "javascript url", getStartLineNumber()); final URL url = getTargetUrl(href, page); final BrowserVersion browser = page.getWebClient().getBrowserVersion(); if (ATTRIBUTE_NOT_DEFINED != getPingAttribute() && browser.hasFeature(ANCHOR_IGNORE_TARGET_FOR_JS_HREF)) { final URL pingUrl = getTargetUrl(getPingAttribute(), page); final WebRequest pingRequest = new WebRequest(pingUrl, HttpMethod.POST); pingRequest.setAdditionalHeader(HttpHeader.PING_FROM, page.getUrl().toExternalForm()); target = page.getResolvedTarget(getTargetAttribute());
/** * Verifies that the specified page contains a link with the specified text. The specified text * may be a substring of the entire text contained by the link. * * @param page the page to check * @param text the text which a link in the specified page is expected to contain */ public static void assertLinkPresentWithText(final HtmlPage page, final String text) { boolean found = false; for (final HtmlAnchor a : page.getAnchors()) { if (a.asText().contains(text)) { found = true; break; } } if (!found) { final String msg = "The page does not contain a link with text '" + text + "'."; throw new AssertionError(msg); } }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { HtmlPage page = webClient.getPage("http://www.google.com"); HtmlAnchor a = page.getHtmlElementById("gb_70"); page = a.click(); HtmlForm form = (HtmlForm) page.getElementById("gaia_loginform"); HtmlTextInput email = (HtmlTextInput) page.getElementById("Email"); email.setValueAttribute(myEmailAddress); HtmlSubmitInput nextButton = page.getHtmlElementById("next"); System.out.println(nextButton.asXml()); HtmlPage newWebpage = nextButton.click(); String status = newWebpage.getWebResponse().getStatusMessage(); System.out.println(status); }
@Test @RunAsClient public final void testSatisfied() throws Exception { UserAgent ua = assertInitialPage(); HtmlPage page = ua.getHomePage(); // Script HtmlAnchor trigger = (HtmlAnchor)page.getElementById("trigger"); trigger.click(); List<String> alerts = ua.getAlerts(page); assertEquals(Arrays.asList("OK MEN"), alerts); // CSS DomNodeList<DomElement> links = page.getElementsByTagName("link"); assertEquals(1, links.size()); HtmlLink link = (HtmlLink)links.get(0); assertTrue(link.getHrefAttribute().endsWith("main.css")); } }
WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = webClient.getPage("https://scholar.google.com/"); HtmlInput searchBox = (HtmlInput) page.getElementById("gs_hp_tsi"); searchBox.setValueAttribute("internet of things for smart cities"); HtmlButton googleSearchSubmitButton = page.getElementByName("btnG"); page = googleSearchSubmitButton.click(); HtmlAnchor anchor = page.getAnchorByText("Cite"); anchor.click(); webClient.waitForBackgroundJavaScript(5000); HtmlAnchor linkBibTex = page.getAnchorByText("BibTeX"); TextPage neededPage = linkBibTex.click(); System.out.println(neededPage.getContent()); webClient.close();
public void testTomcat() throws Exception { HtmlPage page = null; try { page = client.getPage(url); } catch (HttpHostConnectException e) { // sometimes on jenkins there are connections exceptions. // ignoring the rest of the test in this case LOG.error("Failed connecting to tomcat", e); return; } assertEquals("Content Repository Setup", page.getTitleText()); page = submitNewRepositoryForm(page); assertEquals("Content Repository Ready", page.getTitleText()); page = page.getAnchorByText("home").click(); assertEquals("Apache Jackrabbit JCR Server", page.getTitleText()); }
private HtmlAnchor getAnchor(String string) { for (HtmlAnchor n : page.getAnchors()) { if (n.getHrefAttribute().contains(string)) return n; } return null; } /*
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage currentPage = webClient.getPage("http://www.google.com/"); HtmlAnchor advancedSearchAn = currentPage.getAnchorByText("About"); currentPage = advancedSearchAn.click();
HtmlAnchor a = (HtmlAnchor)ele; url = a.getHrefAttribute();
HtmlPage page = webClient.getPage("https://www.yourwebsite.com/#"); HtmlAnchor link=page.getElementByName("link"); link.click(); page.refresh();
/** * Returns the value of the attribute "tabindex". Refer to the * <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a> * documentation for details on the use of this attribute. * * @return the value of the attribute "tabindex" or an empty string if that attribute isn't defined */ public final String getTabIndexAttribute() { return getAttribute("tabindex"); }
private void testSetDescription(String url, TestObject object) throws Exception { object.doSubmitDescription("description"); // test the roundtrip final WebClient wc = j.createWebClient(); HtmlPage page = wc.goTo(url); page.getAnchorByHref("editDescription").click(); wc.waitForBackgroundJavaScript(10000L); HtmlForm form = findForm(page, "submitDescription"); j.submit(form); assertEquals("description", object.getDescription()); }
HtmlAnchor mainPhotoAnchor = new HtmlAnchor(); mainPhotoAnchor.InnerHtml = "<img src=\"" + arrPhotoUrls[0] + "\" class=\"mainPhotoImage\" />"; mainPhotoAnchor.HRef = "javascript:CB_Open('gallery=" + displayAddress + ",,href=" + arrPhotoUrls[0] + "');";
List<HtmlAnchor> anchors1 = page.getAnchors(); HtmlAnchor link2 = null; for(HtmlAnchor anchor: anchors1) { if(anchor.asText().indexOf("Dead Rising 3: Operation Broken Eagle") > -1 ) { link2 = anchor; break; } }
/** * This method will be called if there either wasn't an <tt>onclick</tt> handler, or * there was but the result of that handler was <tt>true</tt>. This is the default * behavior of clicking the element. For this anchor element, the default behavior is * to open the HREF page, or execute the HREF if it is a <tt>javascript:</tt> URL. * * @param defaultPage the default page to return if the action does not load a new page * @return the page that is currently loaded after execution of this method * @throws IOException if an IO error occurs */ @Override protected Page doClickAction(final Page defaultPage) throws IOException { final SgmlPage page = getPage(); final boolean onClickLoadedNewPageInCurrentWindow = defaultPage != page && defaultPage.getEnclosingWindow() == page.getEnclosingWindow(); if (onClickLoadedNewPageInCurrentWindow) { return defaultPage; } return doClickAction(defaultPage, ""); }