/** * unselect a value * * @param value the value to unselect */ @Override @PublicAtsApi public void unsetValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement el : optionElements) { if (el.getText().equals(value)) { if (el.isSelected()) { ((HtmlUnitWebElement) el).click(); UiEngineUtilities.sleep(); } return; } } throw new SeleniumOperationException("Option with label '" + value + "' not found. (" + this.toString() + ")"); }
/** * @return the selected value */ @Override @PublicAtsApi public String[] getValues() { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<String> values = new ArrayList<String>(); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement element : optionElements) { if (element.isSelected()) { values.add(element.getText()); } } if (values.isEmpty()) { throw new SeleniumOperationException("There is no selected 'option' in " + this.toString()); } return values.toArray(new String[0]); }
/** * Check the check box */ @Override @PublicAtsApi public void check() { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); if (!element.isEnabled()) { throw new UnsupportedOperationException("You may not check a disabled element." + toString()); } if (!element.isSelected()) { element.click(); } UiEngineUtilities.sleep(); }
/** * Uncheck the check box */ @Override @PublicAtsApi public void unCheck() { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); if (!element.isEnabled()) { throw new UnsupportedOperationException("You may not uncheck a disabled element." + toString()); } if (element.isSelected()) { element.click(); } UiEngineUtilities.sleep(); }
/** * Select radio button * * @param value of the button to select */ @PublicAtsApi public void select( String value ) { HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this, "[@value='" + value + "']", true); if (!element.isEnabled()) { throw new UnsupportedOperationException("You may not select a disabled element." + toString()); } element.click(); UiEngineUtilities.sleep(); }
/** * set the single selection value * * @param value the value to select */ @Override @PublicAtsApi public void setValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement el : optionElements) { if (el.getText().equals(value)) { ((HtmlUnitWebElement) el).click(); UiEngineUtilities.sleep(); return; } } throw new SeleniumOperationException("Option with label '" + value + "' not found. (" + this.toString() + ")"); }
/** * @return the single selection value */ @Override @PublicAtsApi public String getValue() { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement element : optionElements) { if (element.isSelected()) { return element.getText(); } } throw new SeleniumOperationException("There is no selected 'option' in " + this.toString()); }
/** * @return a list with all possible selection values */ @Override @PublicAtsApi public List<String> getAllPossibleValues() { List<String> values = new ArrayList<String>(); new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); if (optionElements.size() > 0) { for (WebElement element : optionElements) { values.add(element.getText()); } return values; } throw new SeleniumOperationException("There is no selectable 'option' in " + this.toString()); }
private HtmlElement getHtmlUnitElement(HtmlUnitWebElement webElement){ try { boolean changed=false; Field field = HtmlUnitWebElement.class.getDeclaredField("element"); if (!field.isAccessible()) { field.setAccessible(true); changed=true; } HtmlElement htmlElement = (HtmlElement)field.get(webElement); if(changed) field.setAccessible(false); return htmlElement; } catch (Exception e) { throw new Error(e.getMessage(), e); } }
/** * select a value * * @param value the value to select */ @Override @PublicAtsApi public void setValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); if (selectElement.getAttribute("multiple") == null) { throw new SeleniumOperationException("Not a multi-select. You may only add a selection to a select that supports multiple selections. (" + this.toString() + ")"); } List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement el : optionElements) { if (el.getText().equals(value)) { if (!el.isSelected()) { ((HtmlUnitWebElement) el).click(); UiEngineUtilities.sleep(); } return; } } throw new SeleniumOperationException("Option with label '" + value + "' not found. (" + this.toString() + ")"); }
/** * Set the Text Area value * * @param value */ @Override @PublicAtsApi public void setValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); element.clear(); element.sendKeys(value); UiEngineUtilities.sleep(); }
/** * Append text to the current content of a Text Area * * @param value */ @Override @PublicAtsApi public void appendValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); element.sendKeys(value); UiEngineUtilities.sleep(); }
/** * Append text to the current content of a Text Box * * @param value */ @PublicAtsApi public void appendValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); element.sendKeys(value); UiEngineUtilities.sleep(); }
/** * Set the Text Box value * * @param value */ @Override @PublicAtsApi public void setValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this); element.clear(); element.sendKeys(value); UiEngineUtilities.sleep(); }
@Override @PublicAtsApi public boolean isElementEnabled() { try { HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this.element); return element.isEnabled(); } catch (ElementNotFoundException nsee) { return false; } }
/** * Check whether the element is displayed or not * * @return <code>true</code> if the element is displayed */ @Override @PublicAtsApi public boolean isElementDisplayed() { try { HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this.element); return element.isDisplayed(); } catch (ElementNotFoundException nsee) { return false; } }
@Then("^I can download BootsFaces$") public void then_I_can_download_BootsFaces() throws Throwable { WebElement greenButton = driver.findElement(By.className("btn-success")); HtmlUnitWebElement innerSpan = (HtmlUnitWebElement) greenButton.findElement(By.tagName("span")); Assert.assertNotNull(innerSpan); System.out.println("Download button found"); }
@Override public void tab(WebElement element) { //XXX shame we have to do it like this.. if(element instanceof HtmlUnitWebElement) tabOnHtmlUnitElement(element); else { blurUsingJavascript(element); //blurByTypingTabKey(element); } }
public static HtmlUnitWebElement findElement( UiElement uiElement, String xpathSuffix, boolean verbose ) { HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiElement.getUiDriver(); WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name()); HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement); String xpath = uiElement.getElementProperties() .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR); String css = uiElement.getElementProperty("_css"); if (xpathSuffix != null) { xpath += xpathSuffix; } List<WebElement> elements = null; if (!StringUtils.isNullOrEmpty(css)) { elements = webDriver.findElements(By.cssSelector(css)); } else { elements = webDriver.findElements(By.xpath(xpath)); } if (elements.size() == 0) { throw new ElementNotFoundException(uiElement.toString() + " not found."); } else if (elements.size() > 1) { if (verbose) { log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used."); } } HtmlUnitWebElement element = (HtmlUnitWebElement) elements.get(0); if (verbose) { log.info("Found element: " + element.toString()); } return element; }
private void tabOnHtmlUnitElement(WebElement element) { getHtmlUnitElement((HtmlUnitWebElement) element).blur(); }
public static HtmlUnitWebElement findElement( UiElement uiElement ) { return findElement(uiElement, null, true); }