Java 类org.openqa.selenium.htmlunit.HtmlUnitWebElement 实例源码

项目:ats-framework    文件:HiddenHtmlMultiSelectList.java   
/**
 * 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() + ")");
}
项目:ats-framework    文件:HiddenHtmlMultiSelectList.java   
/**
 * @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]);
}
项目:ats-framework    文件:HiddenHtmlCheckBox.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlCheckBox.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlRadioList.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlSingleSelectList.java   
/**
 * 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() + ")");
}
项目:ats-framework    文件:HiddenHtmlSingleSelectList.java   
/**
 * @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());
}
项目:ats-framework    文件:HiddenHtmlSingleSelectList.java   
/**
 * @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());
}
项目:redsniff    文件:SeleniumController.java   
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);
    }
}
项目:ats-framework    文件:HiddenHtmlMultiSelectList.java   
/**
 * 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() + ")");
}
项目:ats-framework    文件:HiddenHtmlTextArea.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlTextArea.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlTextBox.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlTextBox.java   
/**
 * 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();
}
项目:ats-framework    文件:HiddenHtmlElementState.java   
@Override
@PublicAtsApi
public boolean isElementEnabled() {

    try {
        HtmlUnitWebElement element = HiddenHtmlElementLocator.findElement(this.element);
        return element.isEnabled();
    } catch (ElementNotFoundException nsee) {
        return false;
    }
}
项目:ats-framework    文件:HiddenHtmlElementState.java   
/**
 * 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;
    }
}
项目:Cucumber-meets-Selenium    文件:BootsFacesTestDSL.java   
@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");
}
项目:redsniff    文件:SeleniumController.java   
@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);
        }
    }
项目:ats-framework    文件:HiddenHtmlElementLocator.java   
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;
    }
项目:redsniff    文件:SeleniumController.java   
private void tabOnHtmlUnitElement(WebElement element) {
    getHtmlUnitElement((HtmlUnitWebElement) element).blur();
}
项目:ats-framework    文件:HiddenHtmlElementLocator.java   
public static HtmlUnitWebElement findElement( UiElement uiElement ) {

        return findElement(uiElement, null, true);
    }