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; } }
/** * 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); } }
/** * 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); } }
/** * Verifies that the specified page does not contain 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 not expected to contain */ public static void assertLinkNotPresentWithText(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 contains a link with text '" + text + "'."; throw new AssertionError(msg); } }
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); }
@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 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); }