private Describe(Driver driver, WebElement element) { this.driver = driver; this.element = element; sb.append('<').append(element.getTagName()); }
private String serialize() { String text = element.getText(); sb.append('>').append(text == null ? "" : text).append("</").append(element.getTagName()).append('>'); return sb.toString(); }
protected File uploadFile(Driver driver, WebElement inputField, File file) throws IOException { if (!"input".equalsIgnoreCase(inputField.getTagName())) { throw new IllegalArgumentException("Cannot upload file because " + Describe.describe(driver, inputField) + " is not an INPUT"); } if (!file.exists()) { throw new IllegalArgumentException("File not found: " + file.getAbsolutePath()); } String canonicalPath = file.getCanonicalPath(); inputField.sendKeys(canonicalPath); return new File(canonicalPath); }
@Override public String getText() { WebElement webElement = getWebElement(); if ("input".equals(webElement.getTagName().toLowerCase())) { String value = webElement.getAttribute("value"); if (value == null) { value = ""; } return value; } else return getWebElement().getText().trim(); }
@Override public boolean apply(Driver driver, WebElement element) { String elementText = "select".equalsIgnoreCase(element.getTagName()) ? getSelectedOptionsTexts(element) : element.getText(); return Html.text.contains(elementText, this.text.toLowerCase()); }
@Override public String execute(SelenideElement proxy, WebElementSource locator, Object[] args) { WebElement element = locator.getWebElement(); return "select".equalsIgnoreCase(element.getTagName()) ? getSelectedText.execute(proxy, locator, args) : element.getText(); } }
@Override public Boolean execute(SelenideElement proxy, WebElementSource locator, Object[] args) { WebElement img = locator.getWebElement(); if (!"img".equalsIgnoreCase(img.getTagName())) { throw new IllegalArgumentException("Method isImage() is only applicable for img elements"); } return locator.driver().executeJavaScript("return arguments[0].complete && " + "typeof arguments[0].naturalWidth != 'undefined' && " + "arguments[0].naturalWidth > 0", img); } }
@Override public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { String text = (String) args[0]; WebElement element = locator.findAndAssertElementIsInteractable(); if (locator.driver().config().versatileSetValue() && "select".equalsIgnoreCase(element.getTagName())) { selectOptionByValue.execute(proxy, locator, args); return proxy; } if (locator.driver().config().versatileSetValue() && "input".equalsIgnoreCase(element.getTagName()) && "radio".equals(element.getAttribute("type"))) { selectRadio.execute(proxy, locator, args); return proxy; } setValueForTextInput(locator.driver(), element, text); return proxy; }
@Override public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { boolean selected = (Boolean) args[0]; WebElement element = locator.getWebElement(); if (!element.isDisplayed()) { throw new InvalidStateException(locator.driver(), "Cannot change invisible element"); } String tag = element.getTagName(); if (!tag.equals("option")) { if (tag.equals("input")) { String type = element.getAttribute("type"); if (!type.equals("checkbox") && !type.equals("radio")) { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } else { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } if (element.getAttribute("readonly") != null || element.getAttribute("disabled") != null) { throw new InvalidStateException(locator.driver(), "Cannot change value of readonly/disabled element"); } if (element.isSelected() != selected) { click.execute(proxy, locator, NO_ARGS); } return proxy; } }
private Object getInputValue(WebElement input) { Object value = null; String type = input.getAttribute("type"); if ("select".equals(input.getTagName())) { Select select = new Select(input); if (select.isMultiple()) { value = select.getAllSelectedOptions().stream().map(this::getValue) .collect(Collectors.toList()); } else { value = getValue(select.getFirstSelectedOption()); } } else if (Arrays.asList("checkbox", "radio").contains(type)) { if (input.isSelected()) { value = getValue(input); } else { if (Objects.equals(type, "checkbox")) { value = false; } } } else { value = getValue(input); } return value; }
public void verifyUnclickable(WebElement element) { if (element.getTagName().equals("a")) { assertTrue(element.getAttribute("class").contains("disabled")); } else { assertNotNull(element.getAttribute("disabled")); } }
@Override public boolean matchesSafely(WebElement item) { return expectedTagName.equals(item.getTagName()); }
private static boolean isAFormElement(WebElement element) { if ((element == null) || (element.getTagName() == null)) { return false; } String tag = element.getTagName().toLowerCase(); return HTML_FORM_TAGS.contains(tag); }
private boolean isUploadField(WebElement webElement) { boolean tagIsInput = "input".equals(webElement.getTagName()); boolean typeIsFile = "file".equals(webElement.getAttribute("type")); return tagIsInput && typeIsFile; }
try{ WebElement byId = driver.findElement(By.id("by-id")); System.out.println(byId.getTagName()); System.out.println("get the text for web element with id='by-id' "); System.out.println("------------------------------------------------------------"); System.out.println(byId.getText()); System.out.println("------------------------------------------------------------"); System.out.println(byId.getAttribute("id")); System.out.println(byId.getCssValue("font-size")); } }
private boolean isActual(T element) { try { element.get().getTagName(); return true; } catch (Exception ex) { return false; } } @JDIAction(level = DEBUG)
/** * Returns true if at least one of the context elements matches the tag. * * @param tag The tag to match * @return true if at least one of the context elements matches the tag */ public boolean is(String tag) { return getWebElement().getTagName().equalsIgnoreCase(tag); }
protected void blur() { if (SeleniumTestsContextManager.isWebTest() && "input".equalsIgnoreCase(element.getTagName())) { try { ((JavascriptExecutor) driver).executeScript("arguments[0].blur();", element); } catch (Exception e) { logger.error(e); } } }
private Select getSelectElement(String action) { WebElement root = get(); if (root.getTagName().contains("select")) return new Select(root); throw exception(SELECT_ERROR, action, this); }
public ResultType call() throws Exception { response = newResponse(); response.setValue(getElement().getTagName()); return ResultType.SUCCESS; }