/** * Returns the indexed option. * * @param index the index * @return the option specified by the index */ public HtmlOption getOption(final int index) { return this.<HtmlOption>getElementsByTagNameImpl("option").get(index); }
private static void deleteAfter(final DomNode node, final int offset) { if (isOffsetChars(node)) { String text = getText(node); if (offset > -1 && offset < text.length()) { text = text.substring(0, offset); setText(node, text); } } else { final DomNodeList<DomNode> children = node.getChildNodes(); for (int i = offset; i < children.getLength(); i++) { final DomNode child = children.get(i); child.remove(); i--; } } }
private static void deleteAfter(final DomNode node, final int offset) { if (isOffsetChars(node)) { String text = getText(node); if (offset > -1 && offset < text.length()) { text = text.substring(0, offset); setText(node, text); } } else { final DomNodeList<DomNode> children = node.getChildNodes(); for (int i = offset; i < children.getLength(); i++) { final DomNode child = children.get(i); child.remove(); i--; } } }
/** * Returns the indexed option. * * @param index the index * @return the option specified by the index */ public HtmlOption getOption(final int index) { return this.<HtmlOption>getElementsByTagNameImpl("option").get(index); }
private static void deleteBefore(final DomNode node, int offset) { if (isOffsetChars(node)) { String text = getText(node); if (offset > -1 && offset < text.length()) { text = text.substring(offset); } else { text = ""; } setText(node, text); } else { final DomNodeList<DomNode> children = node.getChildNodes(); for (int i = 0; i < offset && i < children.getLength(); i++) { final DomNode child = children.get(i); child.remove(); i--; offset--; } } }
/** * Returns the first element within the document that matches the specified group of selectors. * @param selectors one or more CSS selectors separated by commas * @param <N> the node type * @return null if no matches are found; otherwise, it returns the first matching element */ @SuppressWarnings("unchecked") public <N extends DomNode> N querySelector(final String selectors) { final DomNodeList<DomNode> list = querySelectorAll(selectors); if (!list.isEmpty()) { return (N) list.get(0); } return null; }
private static void deleteBefore(final DomNode node, int offset) { if (isOffsetChars(node)) { String text = getText(node); if (offset > -1 && offset < text.length()) { text = text.substring(offset); } else { text = ""; } setText(node, text); } else { final DomNodeList<DomNode> children = node.getChildNodes(); for (int i = 0; i < offset && i < children.getLength(); i++) { final DomNode child = children.get(i); child.remove(); i--; offset--; } } }
/** * Returns the first element within the document that matches the specified group of selectors. * @param selectors one or more CSS selectors separated by commas * @param <N> the node type * @return null if no matches are found; otherwise, it returns the first matching element */ @SuppressWarnings("unchecked") public <N extends DomNode> N querySelector(final String selectors) { final DomNodeList<DomNode> list = querySelectorAll(selectors); if (!list.isEmpty()) { return (N) list.get(0); } return null; }
public void checkComponentSource(URL pageName, String xmlunitPage, By pageElementToTest) throws IOException, SAXException { WebClient client = new WebClient(); client.getOptions().setJavaScriptEnabled(false); HtmlPage page = client.getPage(pageName); DomElement element; String locator = pageElementToTest.toString(); locator = locator.substring(locator.indexOf(':') + 1).trim(); if (pageElementToTest instanceof ById) { element = page.getElementById(locator); } else if (pageElementToTest instanceof ByTagName) { element = page.getElementsByTagName(locator).get(0); } else { throw new IllegalArgumentException("Only id and name are supported"); } String pageCode = element.asXml(); checkXmlStructure(xmlunitPage, pageCode); }
anchors = cell.getElementsByTagName("a"); for (int x = 0; x < anchors.size(); x++) { HtmlAnchor a = (HtmlAnchor) anchors.get(x); String href = a.getHrefAttribute(); anchors = cell.getElementsByTagName("a"); if (anchors.size() == 1) { HtmlAnchor first = (HtmlAnchor) anchors.get(0); URL url = p.getFullyQualifiedUrl(first.getHrefAttribute()); String href = url.toString(); anchors = cell.getElementsByTagName("a"); for (int x = 0; x < anchors.size(); x++) { HtmlAnchor a = (HtmlAnchor) anchors.get(x); String url = a.getHrefAttribute();
/** * Returns the node to type into. * @return the node */ private DomNode getDoTypeNode() { DomNode node = null; final HTMLElement scriptElement = getScriptableObject(); if (scriptElement.isIsContentEditable() || "on".equals(((Document) scriptElement.getOwnerDocument()).getDesignMode())) { final DomNodeList<DomNode> children = getChildNodes(); if (!children.isEmpty()) { final DomNode lastChild = children.get(children.size() - 1); if (lastChild instanceof DomText) { node = lastChild; } else if (lastChild instanceof HtmlElement) { node = lastChild; } } if (node == null) { final DomText domText = new DomText(getPage(), ""); appendChild(domText); node = domText; } } return node; }
/** * Returns the node to type into. * @return the node */ private DomNode getDoTypeNode() { DomNode node = null; final HTMLElement scriptElement = getScriptableObject(); if (scriptElement.isIsContentEditable() || "on".equals(((Document) scriptElement.getOwnerDocument()).getDesignMode())) { final DomNodeList<DomNode> children = getChildNodes(); if (!children.isEmpty()) { final DomNode lastChild = children.get(children.size() - 1); if (lastChild instanceof DomText) { node = lastChild; } else if (lastChild instanceof HtmlElement) { node = lastChild; } } if (node == null) { final DomText domText = new DomText(getPage(), ""); appendChild(domText); node = domText; } } return node; }
@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")); } }
@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")); } }
@Test public 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(2, links.size()); HtmlLink link1 = (HtmlLink)links.get(0); assertEquals("stylesheet", link1.getRelAttribute()); assertEquals("/juzu/main.css", link1.getHrefAttribute()); assertEquals("text/css", link1.getTypeAttribute()); HtmlLink link2 = (HtmlLink)links.get(1); assertEquals("stylesheet", link2.getRelAttribute()); assertEquals("/juzu/main.less", link2.getHrefAttribute()); assertEquals("text/less", link2.getTypeAttribute()); } }
@Test public 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(2, links.size()); HtmlLink link1 = (HtmlLink)links.get(0); assertEquals("stylesheet", link1.getRelAttribute()); assertEquals("/juzu/main.css", link1.getHrefAttribute()); assertEquals("text/css", link1.getTypeAttribute()); HtmlLink link2 = (HtmlLink)links.get(1); assertEquals("stylesheet", link2.getRelAttribute()); assertEquals("/juzu/main.less", link2.getHrefAttribute()); assertEquals("text/less", link2.getTypeAttribute()); } }