public static String findHidden(HtmlElement elem, String n) { List<HtmlElement> test = elem.getElementsByAttribute("input", "name", n); if (!test.isEmpty()) { HtmlInput i = (HtmlInput) test.get(0); String v = i.getValueAttribute(); if (v != null && v.length() > 0) return v; } return null; }
/** * Returns the first form that matches the specified name. * @param name the name to search for * @return the first form * @exception ElementNotFoundException If no forms match the specified result. */ public HtmlForm getFormByName(final String name) throws ElementNotFoundException { final List<HtmlForm> forms = getDocumentElement().getElementsByAttribute("form", "name", name); if (forms.size() == 0) { throw new ElementNotFoundException("form", "name", name); } return forms.get(0); }
/** * Returns the first form that matches the specified name. * @param name the name to search for * @return the first form * @exception ElementNotFoundException If no forms match the specified result. */ public HtmlForm getFormByName(final String name) throws ElementNotFoundException { final List<HtmlForm> forms = getDocumentElement().getElementsByAttribute("form", "name", name); if (forms.isEmpty()) { throw new ElementNotFoundException("form", "name", name); } return forms.get(0); }
/** * Returns the first form that matches the specified name. * @param name the name to search for * @return the first form * @exception ElementNotFoundException If no forms match the specified result. */ public HtmlForm getFormByName(final String name) throws ElementNotFoundException { final List<HtmlForm> forms = getDocumentElement().getElementsByAttribute("form", "name", name); if (forms.size() == 0) { throw new ElementNotFoundException("form", "name", name); } return forms.get(0); }
/** * Returns the first form that matches the specified name. * @param name the name to search for * @return the first form * @exception ElementNotFoundException If no forms match the specified result. */ public HtmlForm getFormByName(final String name) throws ElementNotFoundException { final List<HtmlForm> forms = getDocumentElement().getElementsByAttribute("form", "name", name); if (forms.size() == 0) { throw new ElementNotFoundException("form", "name", name); } return forms.get(0); }
/** * Returns the first form that matches the specified name. * @param name the name to search for * @return the first form * @exception ElementNotFoundException If no forms match the specified result. */ public HtmlForm getFormByName(final String name) throws ElementNotFoundException { final List<HtmlForm> forms = getDocumentElement().getElementsByAttribute("form", "name", name); if (forms.isEmpty()) { throw new ElementNotFoundException("form", "name", name); } return forms.get(0); }
/** * Searches for an element based on the specified criteria, returning the first element which matches * said criteria. Only elements which are descendants of this element are included in the search. * * @param elementName the name of the element to search for * @param attributeName the name of the attribute to search for * @param attributeValue the value of the attribute to search for * @param <E> the sub-element type * @return the first element which matches the specified search criteria * @throws ElementNotFoundException if no element matches the specified search criteria */ public final <E extends HtmlElement> E getOneHtmlElementByAttribute(final String elementName, final String attributeName, final String attributeValue) throws ElementNotFoundException { WebAssert.notNull("elementName", elementName); WebAssert.notNull("attributeName", attributeName); WebAssert.notNull("attributeValue", attributeValue); final List<E> list = getElementsByAttribute(elementName, attributeName, attributeValue); final int listSize = list.size(); if (listSize == 0) { throw new ElementNotFoundException(elementName, attributeName, attributeValue); } return list.get(0); }
/** * Searches for an element based on the specified criteria, returning the first element which matches * said criteria. Only elements which are descendants of this element are included in the search. * * @param elementName the name of the element to search for * @param attributeName the name of the attribute to search for * @param attributeValue the value of the attribute to search for * @param <E> the sub-element type * @return the first element which matches the specified search criteria * @throws ElementNotFoundException if no element matches the specified search criteria */ public final <E extends HtmlElement> E getOneHtmlElementByAttribute(final String elementName, final String attributeName, final String attributeValue) throws ElementNotFoundException { WebAssert.notNull("elementName", elementName); WebAssert.notNull("attributeName", attributeName); WebAssert.notNull("attributeValue", attributeValue); final List<E> list = getElementsByAttribute(elementName, attributeName, attributeValue); if (list.isEmpty()) { throw new ElementNotFoundException(elementName, attributeName, attributeValue); } return list.get(0); }
/** * Searches for an element based on the specified criteria, returning the first element which matches * said criteria. Only elements which are descendants of this element are included in the search. * * @param elementName the name of the element to search for * @param attributeName the name of the attribute to search for * @param attributeValue the value of the attribute to search for * @param <E> the sub-element type * @return the first element which matches the specified search criteria * @throws ElementNotFoundException if no element matches the specified search criteria */ public final <E extends HtmlElement> E getOneHtmlElementByAttribute(final String elementName, final String attributeName, final String attributeValue) throws ElementNotFoundException { WebAssert.notNull("elementName", elementName); WebAssert.notNull("attributeName", attributeName); WebAssert.notNull("attributeValue", attributeValue); final List<E> list = getElementsByAttribute(elementName, attributeName, attributeValue); final int listSize = list.size(); if (listSize == 0) { throw new ElementNotFoundException(elementName, attributeName, attributeValue); } return list.get(0); }
/** * Searches for an element based on the specified criteria, returning the first element which matches * said criteria. Only elements which are descendants of this element are included in the search. * * @param elementName the name of the element to search for * @param attributeName the name of the attribute to search for * @param attributeValue the value of the attribute to search for * @param <E> the sub-element type * @return the first element which matches the specified search criteria * @throws ElementNotFoundException if no element matches the specified search criteria */ public final <E extends HtmlElement> E getOneHtmlElementByAttribute(final String elementName, final String attributeName, final String attributeValue) throws ElementNotFoundException { WebAssert.notNull("elementName", elementName); WebAssert.notNull("attributeName", attributeName); WebAssert.notNull("attributeValue", attributeValue); final List<E> list = getElementsByAttribute(elementName, attributeName, attributeValue); if (list.isEmpty()) { throw new ElementNotFoundException(elementName, attributeName, attributeValue); } return list.get(0); }
/** * Searches for an element based on the specified criteria, returning the first element which matches * said criteria. Only elements which are descendants of this element are included in the search. * * @param elementName the name of the element to search for * @param attributeName the name of the attribute to search for * @param attributeValue the value of the attribute to search for * @param <E> the sub-element type * @return the first element which matches the specified search criteria * @throws ElementNotFoundException if no element matches the specified search criteria */ public final <E extends HtmlElement> E getOneHtmlElementByAttribute(final String elementName, final String attributeName, final String attributeValue) throws ElementNotFoundException { WebAssert.notNull("elementName", elementName); WebAssert.notNull("attributeName", attributeName); WebAssert.notNull("attributeValue", attributeValue); final List<E> list = getElementsByAttribute(elementName, attributeName, attributeValue); final int listSize = list.size(); if (listSize == 0) { throw new ElementNotFoundException(elementName, attributeName, attributeValue); } return list.get(0); }
/** * Tests that the dropdown list for comment added is populated with the correct values. * @throws Exception if so. */ @Test public void testPopulateDropDown() throws Exception { @SuppressWarnings("unused") List<GerritServer> servers = PluginImpl.getInstance().getServers(); //create a server for testing GerritServer server = new GerritServer(PluginImpl.DEFAULT_SERVER_NAME); servers.add(server); server.start(); FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJobForCommentAdded(j, "myGerritProject"); WebClient wc = j.createWebClient(); HtmlPage page = wc.goTo("job/myGerritProject/configure"); List<HtmlElement> elements = page.getDocumentElement().getElementsByAttribute("td", "class", "setting-name"); HtmlElement tr = null; for (HtmlElement element : elements) { if ("Verdict Category".equals(element.getTextContent())) { tr = element.getEnclosingElement("tr"); break; } } assertNotNull(tr); HtmlElement settingsMainElement = tr.getOneHtmlElementByAttribute("td", "class", "setting-main"); HtmlSelect select = (HtmlSelect)settingsMainElement.getChildElements().iterator().next(); List<String> expected = Arrays.asList("Verified", "Code-Review"); verifyOptions(select, expected); }
WebClient wc = j.createWebClient(); HtmlPage page = wc.goTo("job/myGerritProject/configure"); List<HtmlElement> elements = page.getDocumentElement().getElementsByAttribute("td", "class", "setting-name"); HtmlElement tr = null; for (HtmlElement element : elements) {