List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:org.zanata.page.editor.ReactEditorPage.java
License:Open Source License
public List<WebElement> getTransunitTargets() { log.info("Query Transunit targets"); List<WebElement> targets = new ArrayList<>(); for (WebElement element : getTextUnits()) { if (element.getTagName().trim().equals("textarea")) { targets.add(element);//from w ww . ja va2 s .c o m } } return targets; }
From source file:org.zanata.util.Checkbox.java
License:Open Source License
private Checkbox(WebElement element) { String tagName = element.getTagName(); if (null == tagName || !"input".equals(tagName.toLowerCase())) { throw new UnexpectedTagNameException("input", tagName); }/* w w w. j av a 2 s.com*/ String type = element.getAttribute("type"); if (type == null || !"checkbox".equals(type.toLowerCase())) { throw new IllegalArgumentException("element is not a checkbox"); } this.chkElement = element; }
From source file:org.zaproxy.zap.extension.domxss.TestDomXSS.java
License:Apache License
private void scanHelper(WebDriverWrapper driver, String attackVector, String url) throws DomAlertException { if (this.isStop()) { return;/* w w w. j a v a2 s . c om*/ } try { getHelper(driver, url); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.get1"); throw new DomAlertException(url, attackVector); } List<WebElement> inputElements; try { inputElements = findHelper(driver, By.tagName("input")); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.input1"); throw new DomAlertException(url, attackVector); } for (int i = 0; i < inputElements.size(); i++) { if (this.isStop()) { return; } WebElement element = inputElements.get(i); String tagName = null; String attributeId = null; String attributeName = null; try { // Save for the evidence tagName = element.getTagName(); attributeId = element.getAttribute("id"); attributeName = element.getAttribute("name"); element.sendKeys(attackVector); element.click(); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.input2"); throw new DomAlertException(url, attackVector, tagName, attributeId, attributeName); } catch (WebDriverException wde) { log.debug(wde); } try { getHelper(driver, url); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.get2"); throw new DomAlertException(url, attackVector, tagName, attributeId, attributeName); } try { inputElements = findHelper(driver, By.tagName("input")); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.input3"); throw new DomAlertException(url, attackVector, tagName, attributeId, attributeName); } } List<WebElement> allElements; try { allElements = findHelper(driver, By.tagName("div")); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.div1"); throw new DomAlertException(url, attackVector); } for (int i = 0; i < allElements.size(); i++) { if (this.isStop()) { return; } WebElement element = allElements.get(i); String tagName = null; String attributeId = null; String attributeName = null; try { // Save for the evidence tagName = element.getTagName(); attributeId = element.getAttribute("id"); attributeName = element.getAttribute("name"); element.click(); getHelper(driver, url); allElements = findHelper(driver, By.tagName("div")); } catch (UnhandledAlertException uae) { Stats.incCounter("domxss.vulns.div2"); throw new DomAlertException(url, attackVector, tagName, attributeId, attributeName); } catch (SessionNotFoundException enve) { log.debug(enve); // replaceDriver(driver); } catch (ElementNotVisibleException enve) { log.debug(enve); } catch (TimeoutException wde) { log.debug(wde); } catch (WebDriverException wde) { log.debug(wde); } } }
From source file:piecework.util.E2eTestHelper.java
License:Educational Community License
public static void fillForm(WebDriver driver, String[][] data) { if (driver == null || data == null) { return;/* w w w.j av a 2 s . c o m*/ } //JavascriptExecutor jse = (JavascriptExecutor) driver; for (String[] e : data) { String k = e[0]; String v = e[1]; String byAttr = e.length > 2 ? e[2] : "name"; // default to ByName boolean found = false; for (int i = 0; i < 3; ++i) { try { // System.out.println(k + ", v=" + v + ", i="+ i); WebElement element = null; if (byAttr.equals("id")) { element = driver.findElement(By.id(k)); } else { List<WebElement> elements = driver.findElements(By.name(k)); if (elements.size() == 0) { element = driver.findElement(By.name(k)); // let driver throw exception } else if (elements.size() == 1) { element = elements.get(0); } else { for (int j = 0; j < elements.size(); ++j) { String tagName = elements.get(j).getTagName(); if (tagName.equals("input") || tagName.startsWith("text") || tagName.equals("select")) { element = elements.get(j); String t = element.getAttribute("type"); if (t.equals("hidden")) { element = element.findElement(By.xpath("../input[@type='text']")); } break; } } } } String tagName = element.getTagName(); String t = element.getAttribute("type").toLowerCase(); if (t != null) { t = t.toLowerCase(); } //System.out.println(k + "'s type =" + t); if (tagName.equals("input")) { if (t.equals("hidden")) { WebElement e1 = element.findElement(By.xpath("../input[@data-ng-change]")); e1.sendKeys(v); } else if (t.equals("checkbox") || t.equals("submit")) { element.click(); } else if (t.equals("radio")) { if (v != null && !v.isEmpty()) { WebElement el = element.findElement(By.xpath( "//input[@name='" + k + "' and @type='radio' and @value='" + v + "']")); el.click(); } else { element.click(); } } else if (t.equals("file")) { element.sendKeys(v); Thread.sleep(2000); // for file upload } else { // "text", "date", "datetime" etc. //element.click(); // need this for field with maskedinput (another mask package), but messed up date picker on chrome element.sendKeys(org.openqa.selenium.Keys.HOME); // need this for field with inputmask element.sendKeys(v); } } else if (tagName.startsWith("text")) { element.sendKeys(v); } else if (tagName.equals("select")) { if (v != null && !v.isEmpty()) { WebElement el = element.findElement(By.xpath(".//option[@value='" + v + "']")); el.click(); } else { WebElement el = element.findElement(By.xpath(".//option[1]")); el.click(); } } found = true; break; } catch (Exception ex) { System.out.println(k + ", val=" + v + ", exception =" + ex.toString()); try { Thread.sleep(1000); // wait a bit, then try again } catch (InterruptedException ex1) { } } } // inner loop assertTrue(found, "could not find element <" + k + ">"); } // outer loop }
From source file:piecework.util.E2eTestHelper.java
License:Educational Community License
public static void verifyForm(WebDriver driver, String[][] data) { for (String[] e : data) { String k = e[0];/* w w w. j a v a 2 s. c o m*/ String v = e[1]; String actual = ""; for (int i = 0; i < 3; ++i) { try { WebElement element = driver.findElement(By.xpath(k)); String tagName = element.getTagName(); actual = element.getText(); if ((actual == null || !actual.equals(v)) && (null != element.getAttribute("value"))) { actual = element.getAttribute("value"); } // System.out.println("k="+k+", v="+v+", tag="+tagName+", actual="+actual+", i="+i); if (actual != null && actual.equals(v)) { break; } else { sleep(1); // wait a bit for page to refresh } } catch (Exception ex) { sleep(1); // wait a bit and then try again } } // inner loop assertEquals(actual, v); } // outer loop }
From source file:ru.mystamps.web.tests.WebElementUtils.java
License:Open Source License
public static List<String> convertToListWithText(List<WebElement> elements) { if (elements.isEmpty()) { return Collections.emptyList(); }/*from ww w .j a va 2 s . com*/ List<String> result = new ArrayList<>(elements.size()); for (WebElement el : elements) { String text = null; if ("input".equals(el.getTagName())) { text = el.getAttribute("value"); } else { text = el.getText(); } if (text != null) { result.add(text); } } return result; }
From source file:ru.peterservice.qa.selenium.pagefactory.conditions.ExpectedElementConditions.java
License:Apache License
public static ExpectedElementCondition<Boolean> isNotStale() { return new ExpectedElementCondition<Boolean>() { @Override// w ww .j a va2s . c o m public Boolean apply(WebElement element) { try { element.getTagName(); return true; } catch (StaleElementReferenceException e) { return false; } } }; }
From source file:ru.stqa.selenium.decorated.events.WebDriverListenerTest.java
License:Apache License
@Test void canFireEventForWebElementGetTagName() { Fixture fixture = new Fixture(); final WebElement mockedElement = mock(WebElement.class); when(fixture.mockedDriver.findElement(By.id("id"))).thenReturn(mockedElement); when(mockedElement.getTagName()).thenReturn("input"); assertEquals(fixture.driver.findElement(By.id("id")).getTagName(), "input"); verify(fixture.mockedDriver, times(1)).findElement(By.id("id")); verifyNoMoreInteractions(fixture.mockedDriver); verify(fixture.listener, times(1)).beforeFindElement(fixture.mockedDriver, By.id("id")); verify(fixture.listener, times(1)).afterFindElement(mockedElement, fixture.mockedDriver, By.id("id")); verify(mockedElement, times(1)).getTagName(); verifyNoMoreInteractions(mockedElement); verify(fixture.listener, times(1)).beforeGetTagName(mockedElement); verify(fixture.listener, times(1)).afterGetTagName("input", mockedElement); verifyNoMoreInteractions(fixture.listener); }
From source file:sf.wicklet.gwt.client.test.support.HtmlUnitTestBase.java
License:Apache License
protected void click(final List<WebElement> a) { if (debug().isDebug()) { System.out.println("### click(): " + a.size()); for (final WebElement e : a) { System.out.println(e.getTagName() + ": " + e.getLocation() + ": " + getLink(e)); }/*w w w. j a v a 2s . c o m*/ } if (a.size() > 0) { a.get(0).click(); } }
From source file:sf.wicklet.gwt.client.test.support.HtmlUnitTestBase.java
License:Apache License
protected String getLink(final WebElement e) { switch (e.getTagName()) { case "img": return e.getAttribute("src"); case "form": return e.getAttribute("action"); case "a": default://from ww w. java 2 s . com return e.getAttribute("href"); } }