final HtmlPage pakcagePage = (HtmlPage) mainPage.getFrameByName("packageFrame").getEnclosedPage(); pakcagePage.getAnchors().get(1).click();
final HtmlPage packageListPage = (HtmlPage) mainPage.getFrames().get(0).getEnclosedPage(); packageListPage.getAnchors().get(5).click();
private HtmlAnchor getAnchor(String string) { for (HtmlAnchor n : page.getAnchors()) { if (n.getHrefAttribute().contains(string)) return n; } return null; } /*
WebClient wc = new WebClient(); URL url = new URL("http://www.oogly.co.uk/"); HtmlPage page = (HtmlPage) wc.getPage(url); PrintWriter printWriter = new PrintWriter(new FileWriter(FILE_NAME)); List anchors = page.getAnchors();
public List<WebElement> findElementsByPartialLinkText(String using) { List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); Iterator<HtmlAnchor> allAnchors = anchors.iterator(); List<WebElement> elements = new ArrayList<WebElement>(); while (allAnchors.hasNext()) { HtmlAnchor anchor = allAnchors.next(); if (anchor.asText().contains(using)) { elements.add(newHtmlUnitWebElement(anchor)); } } return elements; } }
private HtmlAnchor getLinkWithText(String linkText, int index) { List<HtmlAnchor> lnks = ((HtmlPage) win.getEnclosedPage()).getAnchors(); int count = 0; for (HtmlAnchor lnk : lnks) { if ((lnk.asText().indexOf(linkText) >= 0) && (count++ == index)) { return lnk; } } return null; }
private HtmlAnchor getLinkWithExactText(String linkText, int index) { List<HtmlAnchor> lnks = ((HtmlPage) win.getEnclosedPage()).getAnchors(); int count = 0; for (HtmlAnchor lnk : lnks) { if ((lnk.asText().equals(linkText)) && (count++ == index)) { return lnk; } } return null; }
@Override public List<WebElement> findElementsByPartialLinkText(String using) { List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); List<WebElement> elements = new ArrayList<>(); for (HtmlAnchor anchor : anchors) { if (anchor.asText().contains(using)) { elements.add(newHtmlUnitWebElement(anchor)); } } return elements; }
public List<WebElement> findElementsByLinkText(String selector) { List<WebElement> elements = new ArrayList<WebElement>(); if (!(lastPage() instanceof HtmlPage)) return elements; int equalsIndex = selector.indexOf('=') + 1; String expectedText = selector.substring(equalsIndex).trim(); List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (expectedText.equals(anchor.asText())) { elements.add(newHtmlUnitWebElement(anchor)); } } return elements; }
@Override public List<WebElement> findElementsByLinkText(String selector) { List<WebElement> elements = new ArrayList<>(); if (!(lastPage() instanceof HtmlPage)) { return elements; } String expectedText = selector.trim(); List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (expectedText.equals(anchor.asText().trim())) { elements.add(newHtmlUnitWebElement(anchor)); } } return elements; }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text */ public HtmlAnchor getAnchorByText(final String text) throws ElementNotFoundException { WebAssert.notNull("text", text); for (final HtmlAnchor anchor : getAnchors()) { if (text.equals(anchor.asText())) { return anchor; } } throw new ElementNotFoundException("a", "<text>", text); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text */ public HtmlAnchor getAnchorByText(final String text) throws ElementNotFoundException { WebAssert.notNull("text", text); for (final HtmlAnchor anchor : getAnchors()) { if (text.equals(anchor.asText())) { return anchor; } } throw new ElementNotFoundException("a", "<text>", text); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text */ public HtmlAnchor getAnchorByText(final String text) throws ElementNotFoundException { WebAssert.notNull("text", text); for (final HtmlAnchor anchor : getAnchors()) { if (text.equals(anchor.asText())) { return anchor; } } throw new ElementNotFoundException("a", "<text>", text); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text */ public HtmlAnchor getAnchorByText(final String text) throws ElementNotFoundException { WebAssert.notNull("text", text); for (final HtmlAnchor anchor : getAnchors()) { if (text.equals(anchor.asText())) { return anchor; } } throw new ElementNotFoundException("a", "<text>", text); }
public WebElement findElementByLinkText(String selector) { int equalsIndex = selector.indexOf('=') + 1; String expectedText = selector.substring(equalsIndex).trim(); if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); } List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (expectedText.equals(anchor.asText())) { return newHtmlUnitWebElement(anchor); } } throw new NoSuchElementException("No link found with text: " + expectedText); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text */ public HtmlAnchor getAnchorByText(final String text) throws ElementNotFoundException { WebAssert.notNull("text", text); for (final HtmlAnchor anchor : getAnchors()) { if (text.equals(anchor.asText())) { return anchor; } } throw new ElementNotFoundException("a", "<text>", text); }
@Override public WebElement findElementByLinkText(String selector) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); } String expectedText = selector.trim(); List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (expectedText.equals(anchor.asText().trim())) { return newHtmlUnitWebElement(anchor); } } throw new NoSuchElementException("No link found with text: " + expectedText); }
public WebElement findElementByPartialLinkText(String using) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); } List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (anchor.asText().contains(using)) { return newHtmlUnitWebElement(anchor); } } throw new NoSuchElementException("No link found with text: " + using); }
@Override public WebElement findElementByPartialLinkText(String using) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); } List<HtmlAnchor> anchors = ((HtmlPage) lastPage()).getAnchors(); for (HtmlAnchor anchor : anchors) { if (anchor.asText().contains(using)) { return newHtmlUnitWebElement(anchor); } } throw new NoSuchElementException("No link found with text: " + using); }
public void assertNoLink(String url) { List<HtmlAnchor> anchors = htmlPage.getAnchors(); boolean found = false; String fullUrl = getHrefFromTestUrl(url); for (HtmlAnchor anchor : anchors) { if (fullUrl.equals(anchor.getHrefAttribute())) { found = true; break; } } assertFalse("Link to " + fullUrl + " found, but should not be present", found); } }