private List<WebElement> convertRawHtmlElementsToWebElements(List<?> nodes) { List<WebElement> elements = new ArrayList<>(); for (Object node : nodes) { if (node instanceof HtmlElement) { elements.add(newHtmlUnitWebElement((HtmlElement) node)); } } return elements; }
private List<WebElement> convertRawHtmlElementsToWebElements(List<?> nodes) { List<WebElement> elements = new ArrayList<WebElement>(); for (Object node : nodes) { if (node instanceof HtmlElement) elements.add(newHtmlUnitWebElement((HtmlElement) node)); } return elements; }
@Override public List<WebElement> findElementsByTagName(String name) { assertElementNotStale(); List<HtmlElement> elements = ((HtmlElement) element).getHtmlElementsByTagName(name); List<WebElement> toReturn = new ArrayList<>(elements.size()); for (HtmlElement element : elements) { toReturn.add(parent.newHtmlUnitWebElement(element)); } return toReturn; }
@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> getElementsByTagName(String tagName) { assertElementNotStale(); List<?> allChildren = element.getByXPath(".//" + tagName); List<WebElement> elements = new ArrayList<WebElement>(); for (Object o : allChildren) { if (!(o instanceof HtmlElement)) continue; HtmlElement child = (HtmlElement) o; elements.add(getParent().newHtmlUnitWebElement(child)); } return elements; }
private WebElement findParentForm() { DomNode current = element; while (!(current == null || current instanceof HtmlForm)) { current = current.getParentNode(); } return getParent().newHtmlUnitWebElement((HtmlForm) current); }
private WebElement findParentForm() { DomNode current = element; while (!(current == null || current instanceof HtmlForm)) { current = current.getParentNode(); } return getParent().newHtmlUnitWebElement((HtmlForm) current); }
public List<WebElement> findElementsByXPath(String xpathExpr) { assertElementNotStale(); List<WebElement> webElements = new ArrayList<WebElement>(); List<?> htmlElements = element.getByXPath(xpathExpr); for (Object e : htmlElements) { webElements.add(getParent().newHtmlUnitWebElement((HtmlElement) e)); } return webElements; }
public List<WebElement> getElementsByTagName(String tagName) { assertElementNotStale(); List<?> allChildren = element.getByXPath(".//" + tagName); List<WebElement> elements = new ArrayList<>(); for (Object o : allChildren) { if (!(o instanceof HtmlElement)) { continue; } HtmlElement child = (HtmlElement) o; elements.add(getParent().newHtmlUnitWebElement(child)); } return elements; }
@Override public List<WebElement> findElementsByLinkText(String linkText) { assertElementNotStale(); String expectedText = linkText.trim(); List<? extends HtmlElement> htmlElements = ((HtmlElement) element).getHtmlElementsByTagName("a"); List<WebElement> webElements = new ArrayList<>(); for (DomElement e : htmlElements) { if (expectedText.equals(e.getTextContent().trim()) && e.getAttribute("href") != null) { webElements.add(getParent().newHtmlUnitWebElement(e)); } } return webElements; }
public WebElement findElementByTagName(String name) { if (!(lastPage() instanceof HtmlPage)) throw new IllegalStateException("Cannot find element by name for " + lastPage()); NodeList allElements = ((HtmlPage) lastPage()).getElementsByTagName(name); if (allElements.getLength() > 0) { return newHtmlUnitWebElement((HtmlElement) allElements.item(0)); } throw new NoSuchElementException("Cannot find element with name: " + name); }
@Override public WebElement findElementByTagName(String name) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Unable to locate element by name for " + lastPage()); } NodeList allElements = ((HtmlPage) lastPage()).getElementsByTagName(name); if (allElements.getLength() > 0) { return newHtmlUnitWebElement((HtmlElement) allElements.item(0)); } throw new NoSuchElementException("Unable to locate element with name: " + name); }
@Override public WebElement findElementByName(String name) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Unable to locate element by name for " + lastPage()); } List<DomElement> allElements = ((HtmlPage) lastPage()).getElementsByName(name); if (!allElements.isEmpty()) { return newHtmlUnitWebElement(allElements.get(0)); } throw new NoSuchElementException("Unable to locate element with name: " + name); }
public WebElement findElementByName(String name) { if (!(lastPage() instanceof HtmlPage)) throw new IllegalStateException("Cannot find element by name for " + lastPage()); List<HtmlElement> allElements = ((HtmlPage) lastPage()).getElementsByName(name); if (allElements.size() > 0) { return newHtmlUnitWebElement(allElements.get(0)); } throw new NoSuchElementException("Cannot find element with name: " + name); }
public WebElement findElementByXPath(String selector) { if (!(lastPage() instanceof HtmlPage)) throw new IllegalStateException("Cannot find element by xpath for " + lastPage()); Object node = ((HtmlPage) lastPage()).getFirstByXPath(selector); if (node == null) throw new NoSuchElementException("Cannot locate a node using " + selector); if (node instanceof HtmlElement) return newHtmlUnitWebElement((HtmlElement) node); throw new NoSuchElementException(String.format("Cannot find element with xpath %s", selector)); }
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 WebElement findElementByXPath(String xpathExpr) { assertElementNotStale(); HtmlElement match = (HtmlElement) element.getFirstByXPath(xpathExpr); if (match == null) { throw new NoSuchElementException("Unable to find element with xpath " + xpathExpr); } return getParent().newHtmlUnitWebElement(match); }
@Override public WebElement findElementById(String id) { if (!(lastPage() instanceof HtmlPage)) { throw new NoSuchElementException("Unable to locate element by id for " + lastPage()); } try { HtmlElement element = ((HtmlPage) lastPage()).getHtmlElementById(id); return newHtmlUnitWebElement(element); } catch (ElementNotFoundException e) { throw new NoSuchElementException("Unable to locate element with ID: " + id); } }
public WebElement findElementById(String id) { if (!(lastPage() instanceof HtmlPage)) throw new NoSuchElementException("Cannot find element by id for " + lastPage()); try { HtmlElement element = ((HtmlPage) lastPage()).getHtmlElementById(id); return newHtmlUnitWebElement(element); } catch (ElementNotFoundException e) { throw new NoSuchElementException("Cannot find element with ID: " + id); } }