List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:io.github.seleniumquery.by.firstgen.css.pseudoclasses.SubmitPseudoClass.java
License:Apache License
private boolean inputWithTypeSubmit(WebElement element) { return INPUT.equals(element.getTagName()) && SUBMIT.equalsIgnoreCase(element.getAttribute("type")); }
From source file:io.github.seleniumquery.by.firstgen.css.pseudoclasses.SubmitPseudoClass.java
License:Apache License
private boolean buttonWithTypeSubmitOrWithoutType(WebElement element) { boolean isButtonTag = BUTTON.equals(element.getTagName()); if (!isButtonTag) { return false; }/*from w w w . j a v a2 s .co m*/ boolean isTypeSubmit = SUBMIT.equalsIgnoreCase(element.getAttribute("type")); boolean isTypeNull = element.getAttribute("type") == null; return isTypeSubmit || isTypeNull; }
From source file:io.github.seleniumquery.by.firstgen.css.pseudoclasses.TextPseudoClass.java
License:Apache License
@Override public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) { return "input".equals(element.getTagName()) && (element.getAttribute("type") == null || "text".equalsIgnoreCase(element.getAttribute("type"))); }
From source file:io.github.seleniumquery.by.firstgen.css.tagname.TagNameSelector.java
License:Apache License
@Override public boolean is(WebDriver driver, WebElement element, ArgumentMap argumentMap, ElementSelector elementSelector) { String name = elementSelector.getLocalName(); return isBlank(name) || name.equalsIgnoreCase(element.getTagName()); }
From source file:io.github.seleniumquery.functions.jquery.events.ClickFunctionUtils.java
License:Apache License
public static String toString(WebElement element) { return "\n\t id attribute: \"" + element.getAttribute("id") + "\"" + "\n\t class attribute: \"" + element.getAttribute("class") + "\"" + "\n\t name attribute: \"" + element.getAttribute("name") + "\"" + "\n\t tag: \"" + element.getTagName() + "\"" + "\n\t text: \"" + element.getText() + "\"" + "\n\t value attribute: " + element.getAttribute("value") + "\"" + "\n\t size()/dimension: " + element.getSize() + "\n\t isDisplayed(): " + element.isDisplayed() + "\n\t isEnabled(): " + element.isEnabled() + "\n\t toString(): " + element + "\n"; }
From source file:io.github.seleniumquery.functions.jquery.forms.FocusFunction.java
License:Apache License
private static void focusElement(WebDriver driver, WebElement elementToBeFocused) { // #Cross-Driver if (DriverVersionUtils.getInstance().isHtmlUnitDriver(driver) && "html".equals(elementToBeFocused.getTagName())) { LOGGER.warn("The HTML element is not focusable in HtmlUnitDriver, even with a tabindex attribute!"); }// ww w . j a v a 2s. c o m elementToBeFocused.sendKeys(Keys.NULL); }
From source file:io.github.seleniumquery.functions.jquery.forms.ValFunction.java
License:Apache License
/** * <p>Gets the value of the given element, if its tag name is INPUT, OPTION, SELECT or TEXTAREA.</p> * Otherwise it returns an empty string. * * @param element The element you want the value of. * @return The value of the element.// w w w . ja v a 2s . com * @since 0.9.0 */ public static String val(WebElement element) { String tagName = element.getTagName(); if (isInputTag(element) || isOptionTag(element)) { return element.getAttribute("value"); } else if (isSelectTag(element)) { Select select = new Select(element); if (select.isMultiple()) return select.getAllSelectedOptions().stream().map(we -> we.getAttribute("value")) .collect(Collectors.joining(",")); else return select.getFirstSelectedOption().getAttribute("value"); } else if (isTextareaTag(element)) { // see issue#59 - <textarea> returns wrong value (original value) for getText() in Firefox // It used to be element.getText(). We use .getAttribute("value") because it works for everyone. return element.getAttribute("value"); } LOGGER.warn("Attempting to call .val() in an element of type '" + tagName + "': " + element + ". Returning empty string."); return ""; }
From source file:io.github.seleniumquery.functions.jquery.manipulation.HtmlFunction.java
License:Apache License
private static String getHtmlForHtmlUnitDriver(WebElement element) { String html = getHtmlUnitInnerHTML((HtmlUnitWebElement) element); // #Cross-Driver // HtmlUnitDriver does not append a "\n" to the HTML of the body tag // as Chrome, Firefox and IE10 seem to. // So we add it! if ("body".equals(element.getTagName())) { return html + "\n"; }// w ww . java 2 s. co m return html; }
From source file:io.github.seleniumquery.utils.SelectorUtils.java
License:Apache License
private static WebElement parentByXPath(WebElement element) { if ("html".equalsIgnoreCase(element.getTagName())) { try {/*w ww. j a v a 2 s . c o m*/ WebElement parent = parentByXPathExpression(element); parent.getTagName(); // trigger exception on firefox #Cross-Driver return parent; } catch (InvalidSelectorException | StaleElementReferenceException e) { if (e.getMessage().contains("HTMLDocument") || e.getMessage().contains("htmlunit.html.HtmlPage")) { // #Cross-Driver // chrome throws InvalidSelectorException: invalid selector: The result of the xpath expression ".." is: [object HTMLDocument]. It should be an element. // opera throws InvalidSelectorException: invalid selector: The result of the xpath expression ".." is: [object HTMLDocument]. It should be an element. // ie throws InvalidSelectorException: The result of the xpath expression ".." is: [object HTMLDocument]. It should be an element. // edge: see below // phantomjs throws InvalidSelectorException: {"errorMessage":"The result of the xpath expression \"..\" is: [object HTMLDocument]. It should be an element." ...} // htmlunit throws InvalidSelectorException: The xpath expression '..' selected an object of type 'class com.gargoylesoftware.htmlunit.html.HtmlPage' instead of a WebElement // firefox throws StaleElementReferenceException: The element reference of [object HTMLDocument] {...} stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed LOGGER.debug("parent() on element (" + element + ") failed. It probably is because element is <html>. Still, it could be something else, thus this logging.", e); } else { throw e; } } catch (NoSuchElementException e) { // edge throws NoSuchElementException: No such element (WARNING: The server did not provide any stacktrace information) LOGGER.debug("parent() on element (" + element + ") failed. It probably is because element is <html>. Still, it could be something else, thus this logging.", e); } return null; } else { return parentByXPathExpression(element); } }
From source file:io.github.seleniumquery.utils.WebElementUtils.java
License:Apache License
public static boolean isTextareaTag(WebElement element) { return "textarea".equals(element.getTagName()); }