List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:org.specrunner.webdriver.assertions.PluginCompareUtils.java
License:Open Source License
/** * Compare two elements and return the number of errors in comparison. * // w w w . ja v a 2 s .c om * @param compare * The compare plugin. * @param context * The context. * @param result * The result. * @param e * The expected content. * @param we * The received content. * @param errors * The errors count. * @return The errors count adjusted. */ protected static int compareElements(PluginCompareNode compare, IContext context, IResultSet result, Element e, WebElement we, int errors) { errors = compareTexts(compare, context, result, e, we, errors); if (!e.getLocalName().equalsIgnoreCase(we.getTagName())) { errors++; result.addResult(Failure.INSTANCE, context.newBlock(e, compare), new PluginException("Tag names do not match (expected: '" + e.getLocalName() + "', received: '" + we.getTagName() + "'.")); } for (int j = 0; j < e.getAttributeCount(); j++) { Attribute att = e.getAttribute(j); String name = att.getLocalName(); String attExp = e.getAttributeValue(name); String attRec = we.getAttribute(name); if (attRec == null) { errors++; result.addResult(Failure.INSTANCE, context.newBlock(e, compare), new PluginException( "Attribute '" + name + "' missing (expected: '" + name + "=" + attExp + "').")); continue; } String attRecNorm = compare.getNormalized(attRec); String attExpNorm = compare.getNormalized(attExp); boolean match = (compare.getContains() && attRecNorm.contains(attExpNorm)) || attExpNorm.equals(attRecNorm); if (!match) { errors++; result.addResult(Failure.INSTANCE, context.newBlock(e, compare), new PluginException("Attribute '" + name + "' does not match (expected: '" + attExp + "', received: '" + attRec + "').")); } } return errors; }
From source file:org.sugarcrm.voodoodriver.EventLoop.java
License:Apache License
/** * Filter elements by HTML element type//ww w . ja v a 2 s. co m * * Take a list of {@link WebElement}s found using the event selection * criteria and filter through by HTML tag type. * * @param elements element list returned based on event * @param event current event * @return list of elements filtered by HTML tag */ private List<WebElement> filterElements(List<WebElement> elements, VDDHash event) { ArrayList<WebElement> filtered = new ArrayList<WebElement>(elements.size()); String html_tag = (String) event.get("html_tag"); String html_type = (String) event.get("html_type"); for (int k = 0; k < elements.size(); k++) { WebElement e = elements.get(k); if (checkMatch(e.getTagName(), html_tag) && checkMatch(e.getAttribute("type"), html_type)) { filtered.add(e); } } return filtered; }
From source file:org.suren.autotest.web.framework.selenium.action.multi.SeleniumMultiValueEditor.java
License:Apache License
@Override public void setValue(Element ele, Object value) { ElementsSearchStrategy<WebElement> strategy = searchStrategyUtils.findElementsStrategy(WebElement.class, ele);/*from w w w .ja v a 2 s .co m*/ List<WebElement> eleList = strategy.searchAll(ele); for (int i = 0; i < eleList.size(); i++) { WebElement webEle = eleList.get(i); String tagName = webEle.getTagName(); String text = webEle.getText(); String attrName = null; String attrValue = null; if (!webEle.isDisplayed()) { continue; } if (filter.filter(tagName, attrName, attrValue, text)) { webEle.sendKeys(value.toString()); } } }
From source file:org.testeditor.fixture.web.EclipseRapFixture.java
License:Open Source License
/** * Refines the behavior of the super class, such that the target element is * clicked once more, after the given <code>value</code> has been inserted * into the target element./*from w w w . ja v a 2s. co m*/ * * @param elementListKey * key to find the technical locator * @param value * value for the input * @param replaceArgs * values to replace the place holders in the element list entry * with * @return true if input was successful, otherwise false */ @Override public void insertIntoField(String value, String elementListKey, String... replaceArgs) { WebElement element = findWebelement(elementListKey, replaceArgs); if (element != null && element.isDisplayed()) { element.click(); element.sendKeys(value); // for a non-wrapping textarea this click caused an exception if (!element.getTagName().equalsIgnoreCase("textarea")) { waitTime(500); element.click(); } String expectedValue; if (element.getTagName().equalsIgnoreCase("input")) { expectedValue = readAttributeFromField("value", elementListKey, replaceArgs); } else { // resolve to cheating (i.e. no plausibility checks) for // problematic cases e.g. for div elements in date selection // widgets expectedValue = value; } if (assertIsEqualTo(value, expectedValue)) { throw new StopTestException("Value wasn't inserted correctly"); } } }
From source file:org.testeditor.fixture.web.HtmlWebFixture.java
License:Open Source License
/** * Returns the value of the given web element. If the element has no value * attribute, the element text is returned. * //from w ww . j av a 2 s . c o m * @param elementListKey * key in the element list to find the technical locator * @param replaceArgs * values to replace the place holders in the element list entry * @return the {@code value} or {@code text} of the element * @throws StopTestException * if element not available (hidden, not present) or a timeout * occurred */ // CHECKSTYLE:OFF public String readValueOfElement(String elementListKey, String... replaceArgs) throws StopTestException { // CHECKSTYLE:ON WebElement element = findAvailableWebElement(elementListKey, replaceArgs); String value = null; switch (element.getTagName()) { case "input": String type = element.getAttribute("type"); // handle check-box and radio-button different if ("checkbox".equalsIgnoreCase(type) || "radio".equalsIgnoreCase(type)) { value = getSelectionOfRadioButtonOrCheckBox(elementListKey, replaceArgs); break; } case "option": case "li": case "button": case "param": case "progress": value = element.getAttribute("value"); break; case "select": value = new Select(element).getFirstSelectedOption().getAttribute("value"); break; case "img": case "source": value = element.getAttribute("src"); break; default: // used by <a>, <body>, <div>, <textarea>, ... value = element.getText(); break; } // CHECKSTYLE:OFF return value == null ? "" : value.trim(); // CHECKSTYLE:ON }
From source file:org.testeditor.fixture.web.WebDriverFixture.java
License:Open Source License
protected String getValueOfWebElement(WebElement element) { String value = null;// ww w . j a v a 2 s . c o m String readValueThroughText = element.getText(); // Selenium getText() vs. getAttribute("value") see https://sqa.stackexchange.com/questions/24463/selenium-webdriver-gettext-vs-getattribute if ((readValueThroughText != null) && (!readValueThroughText.isEmpty())) { value = readValueThroughText; logger.trace("readValueThroughText -> element.getText() returned elements successfully"); } else { String readValueThroughAttribute = element.getAttribute("value"); if ((readValueThroughAttribute != null) && (!readValueThroughAttribute.isEmpty())) { value = readValueThroughAttribute; logger.trace("readValueThroughAttribute -> element.getAttribute(\"value\") returned " + "elements successfully {}"); } else { logger.trace("readValueThroughAttribute -> element.getAttribute(\"value\") and element.getText() " + "returned no result for element {}", element.getTagName()); value = null; } } logger.trace("getValueOfWebElement returned: \n{} for element {}", value, element.getTagName()); return value; }
From source file:org.testeditor.fixture.web.WebFixture.java
License:Open Source License
/** * Inserts the given value into an input field and checks if input was * successful. The technical locator of the field gets identified by the * element list matching the given key. <br /> * //from w ww. java 2s. c om * FitNesse usage..: |insert|arg1|into field;|arg2|[arg3, arg4, ...]| <br /> * FitNesse example: |insert|Some Text|into field;|TextboxInRow{0}Col{1}|[5, * 3]| <br /> * <br /> * * @param elementListKey * key to find the technical locator * @param value * value for the input * @param replaceArgs * values to replace the place holders in the element list entry * with * @return true if input was successful, otherwise false */ public void insertIntoField(String value, String elementListKey, String... replaceArgs) { WebElement element = findWebelement(elementListKey, replaceArgs); if (element != null && element.isDisplayed()) { element.click(); element.sendKeys(value); String expectedValue = null; if (element.getTagName().equalsIgnoreCase("select")) { Select s = new Select(element); expectedValue = s.getFirstSelectedOption().getText(); } else { expectedValue = readAttributeFromField("value", elementListKey, replaceArgs); } if (!assertIsEqualTo(value, expectedValue)) { throw new StopTestException("Value wasn't inserted correctly"); } } }
From source file:org.testeditor.ui.uiscanner.expressions.ExpressionBaseContains.java
License:Open Source License
/** * Evaluate the Attribute value from the given WebElement with the Value. * //from w ww . j a va 2 s. c om * @param element * WebElement to check. * @return true if the Value of the Attribute is equals the Value Attribute * of the WebElement else false. */ public boolean evalute(WebElement element) { if (getAttribut().equals("tagname")) { return element.getTagName().contains(getValue()); } else if (element.getAttribute(getAttribut()) == null) { return false; } return element.getAttribute(getAttribut()).contains(getValue()); }
From source file:org.testeditor.ui.uiscanner.expressions.ExpressionBaseEqual.java
License:Open Source License
/** * Evaluate the Attribute value from the given WebElement with the Value. * //from w ww. ja v a2 s . c o m * @param element * WebElement to check. * @return true if the Value of the Attribute is equals the Value Attribute * of the WebElement else false. */ public boolean evalute(WebElement element) { if (getAttribut().equals("tagname")) { return element.getTagName().equals(getValue()); } else if (element.getAttribute(getAttribut()) == null) { return false; } return element.getAttribute(getAttribut()).equals(getValue()); }
From source file:org.unit.GlobalSearch.java
License:Apache License
@Test public void findFirstShouldReturnFirst() { String name = "cssStyle"; WebElement webElement1 = mock(WebElement.class); when(webElement1.getTagName()).thenReturn("span"); WebElement webElement2 = mock(WebElement.class); when(webElement2.getTagName()).thenReturn("a"); List<WebElement> webElements = new ArrayList<WebElement>(); webElements.add(webElement1);//from w w w. j a va 2 s.c om webElements.add(webElement2); when(searchContext.findElements(By.cssSelector("cssStyle"))).thenReturn(webElements); FluentWebElement fluentWebElement = search.findFirst(name, null); assertThat(fluentWebElement.getTagName()).isEqualTo("span"); }