List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:com.opera.core.systems.FindElementsTest.java
License:Apache License
@Test public void testElementsPartialLinkText() { List<WebElement> els = driver.findElementsByPartialLinkText("te"); for (WebElement el : els) { assertTrue(el.getText().contains("te")); assertEquals(el.getTagName().toLowerCase(), "a"); }//www . jav a 2s.c o m }
From source file:com.opera.core.systems.FindElementsTest.java
License:Apache License
@Test public void testId() { WebElement el = driver.findElementById("call-to-action"); assertEquals(el.getAttribute("id"), "call-to-action"); assertEquals(el.getTagName().toLowerCase(), "p"); }
From source file:com.opera.core.systems.FindElementsTest.java
License:Apache License
public void testElementsXPath() { List<WebElement> els = driver.findElementsByXPath("//span"); for (WebElement el : els) { assertEquals(el.getTagName().toLowerCase(), "span"); }//from w w w . j av a 2 s .c om }
From source file:com.opera.core.systems.FindElementsTest.java
License:Apache License
@Test public void testElementsTagName() { List<WebElement> els = driver.findElementsByTagName("label"); assertEquals(4, els.size());// w ww. j av a 2s . co m for (WebElement el : els) { assertEquals(el.getTagName(), "LABEL"); } }
From source file:com.opera.core.systems.FindElementsTest.java
License:Apache License
@Test public void testMultipleElements() throws Exception { OperaWebElement form = (OperaWebElement) driver.findElementByTagName("form"); List<WebElement> els = form.findElements(By.tagName("input")); Assert.assertEquals(5, els.size());//w w w . j av a 2 s .com for (WebElement el : els) { Assert.assertEquals(el.getTagName(), "INPUT"); } }
From source file:com.partnet.automation.HtmlView.java
License:Apache License
/** * Parses through an html description list (tag = dl) and puts the description * term (tag = dt) as the key in the map and puts the description description * (tag = dd) as the value in map//from w ww . j a v a 2 s. c o m * * @param termsAndDescriptions * - this must be a list of dt and dd {@link WebElement} * @return Map */ protected Map<String, String> parseDescriptionList(final List<WebElement> termsAndDescriptions) { Map<String, String> descriptionList = new HashMap<>(termsAndDescriptions.size()); String term = null; for (WebElement elt : termsAndDescriptions) // the WebElement expected is // the array of a dl's dt/dd // WebElements { String tag = elt.getTagName(); // this gets the tag type. It is expecting // either dt or dd String taggedText = elt.getText().trim(); // this gets the value that is // tagged LOG.debug("tag({}) text({})", tag, taggedText); if (tag.equals("dt")) { // if tag is <dt> description list term; the "key" // in the map term = taggedText; } else if (tag.equals("dd")) { // if tag is <dl> description list // description/definition; the "value" in the // map String previousValue = descriptionList.put(term, taggedText); if (previousValue != null) { throw new IllegalStateException( String.format("Unexpected condition - key (%s) with multiple values (%s) and (%s)", term, previousValue, taggedText)); } } else { throw new IllegalArgumentException("Unexpected tag in description list, tag is " + tag); } } return descriptionList; }
From source file:com.redskyit.scriptDriver.RunTests.java
License:MIT License
private void info(WebElement element, String selector, boolean verify) throws Exception { do {// w w w .ja v a 2 s.c om try { Point loc = element.getLocation(); Dimension size = element.getSize(); String tag = element.getTagName(); System.out .print(null == selector ? "test-id \"" + element.getAttribute("test-id") + "\"" : selector); System.out.print(" info"); System.out.print(" tag " + tag); System.out.print((element.isDisplayed() ? "" : " not") + " displayed"); System.out.print(" at " + loc.x + "," + loc.y); System.out.print(" size " + size.width + "," + size.height); System.out.print((element.isEnabled() ? "" : " not") + " enabled"); System.out.print((element.isSelected() ? "" : " not") + " selected"); if (tag.equals("input") || tag.equals("select")) { System.out.print(" check \"" + element.getAttribute("value") + "\""); } else { String text = tag.equals("textarea") ? element.getAttribute("value") : element.getText(); if (text.indexOf('\n') != -1) { CRC32 crc = new CRC32(); crc.update(text.getBytes()); System.out.print(" checksum \"crc32:" + crc.getValue() + "\""); } else { System.out.print(" check \"" + element.getText() + "\""); } } System.out.println(); return; } catch (StaleElementReferenceException e) { // If element has gone stale during a dump, ignore it if (!verify) return; // element has gone stale, re-select it System.out.println("// EXCEPTION : StaleElementReference"); } catch (Exception e) { if (verify) throw e; return; } sleepAndReselect(100); } while (_waitFor > 0 && (new Date()).getTime() < _waitFor); }
From source file:com.redspr.redrobot.WebDriverRobot.java
License:Open Source License
@Override public String get(String... x) { WebElement elmt = locKey(x); if ("select".equals(elmt.getTagName())) { Select select = new Select(elmt); return select.getFirstSelectedOption().getText(); }/*from ww w . j av a2s. co m*/ String r = elmt.getAttribute("value"); if (r == null) { r = elmt.getText(); } return r.replaceAll("\\r", ""); }
From source file:com.redspr.redrobot.WebDriverRobot.java
License:Open Source License
@Override public void set(String... x) { String[] n = allButLast(x);//from w ww.j a va 2 s.com String v = x[x.length - 1]; WebElement e = this.locKey(n); try { if ("select".equals(e.getTagName())) { e.sendKeys(v); } else { JavascriptExecutor js = (JavascriptExecutor) webDriver; js.executeScript( "if (arguments[0].value != arguments[1]) {arguments[0].value = arguments[1]; arguments[0].dispatchEvent(new Event('change'))}", e, v); } } catch (WebDriverException ex) { throw new RuntimeException( "Failed trying to set name='" + e.getTagName() + "' to text='" + e.getText() + "'", ex); } waitTillReady(); }
From source file:com.screenslicer.core.scrape.QueryForm.java
License:Open Source License
private static HtmlNode toFormControl(WebElement element) { if (!element.isDisplayed()) { return null; }//from w w w.j ava2 s . co m HtmlNode control = new HtmlNode(); control.tagName = element.getTagName(); String attr = element.getAttribute("name"); control.name = CommonUtil.isEmpty(attr) ? null : attr; attr = element.getAttribute("title"); control.title = CommonUtil.isEmpty(attr) ? null : attr; attr = element.getAttribute("id"); control.id = CommonUtil.isEmpty(attr) ? null : attr; attr = element.getAttribute("type"); control.type = CommonUtil.isEmpty(attr) ? null : attr; attr = element.getAttribute("value"); control.value = CommonUtil.isEmpty(attr) ? null : attr; attr = element.getAttribute("innerHTML"); control.innerHtml = CommonUtil.isEmpty(attr) ? null : attr; if ("hidden".equalsIgnoreCase(control.type)) { return null; } return control; }