Example usage for org.openqa.selenium WebElement isSelected

List of usage examples for org.openqa.selenium WebElement isSelected

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement isSelected.

Prototype

boolean isSelected();

Source Link

Document

Determine whether or not this element is selected or not.

Usage

From source file:org.safs.selenium.webdriver.lib.interpreter.selrunner.steptype.Check.java

License:Open Source License

@Override
public boolean run(TestRun ctx) {

    // select locator
    WebElement checkbox = ctx.locator(WDScriptFactory.LOCATOR_PARAM).find(ctx);
    if (checkbox == null) {
        ctx.log().error("Check did not find any matching WebElement.");
        return false;
    }//  w ww  .  j a v a2 s  .c om
    try {
        if (!checkbox.isSelected()) {
            checkbox.click();
        } else {
            ctx.log().info("Item is already selected. No attempt to Check will be made.");
        }
        return true;
    } catch (Exception x) {
        ctx.log().error("Check " + x.getClass().getSimpleName() + ", " + x.getMessage());
        return false;
    }
}

From source file:org.safs.selenium.webdriver.lib.interpreter.selrunner.steptype.Uncheck.java

License:Open Source License

@Override
public boolean run(TestRun ctx) {

    // select locator
    WebElement checkbox = ctx.locator(WDScriptFactory.LOCATOR_PARAM).find(ctx);
    if (checkbox == null) {
        ctx.log().error("Uncheck did not find any matching WebElement.");
        return false;
    }/*from www.jav  a2  s  . co m*/
    try {
        if (checkbox.isSelected()) {
            checkbox.click();
        } else {
            ctx.log().info("Item is not selected. No attempt to Uncheck will be made.");
        }
        return true;
    } catch (Exception x) {
        ctx.log().error("Uncheck " + x.getClass().getSimpleName() + ", " + x.getMessage());
        return false;
    }
}

From source file:org.specrunner.webdriver.actions.PluginCheck.java

License:Open Source License

@Override
protected void doSomething(WebElement option) {
    if (!option.isSelected()) {
        option.click();
    }
}

From source file:org.specrunner.webdriver.actions.PluginSelect.java

License:Open Source License

@Override
protected void doSomething(WebElement element, WebElement option) {
    if (!option.isSelected()) {
        option.click();
    }
}

From source file:org.specrunner.webdriver.actions.PluginUncheck.java

License:Open Source License

@Override
protected void doSomething(WebElement option) {
    if (option.isSelected()) {
        option.click();
    }
}

From source file:org.specrunner.webdriver.actions.PluginUnselect.java

License:Open Source License

@Override
protected void doSomething(WebElement element, WebElement option) {
    if (option.isSelected()) {
        option.click();
    }
}

From source file:org.specrunner.webdriver.assertions.AbstractPluginCheckable.java

License:Open Source License

@Override
protected void process(IContext context, IResultSet result, WebDriver client, WebElement[] elements)
        throws PluginException {
    boolean error = false;
    for (WebElement element : elements) {
        if (isCheckbox(element) || isRadio(element)) {
            boolean componentStatus = element.isSelected();
            if (expected() != componentStatus) {
                result.addResult(Failure.INSTANCE, context.peek(),
                        new PluginException("Element " + getFinderInstance().resume(context) + " should be '"
                                + (expected() ? "checked" : "unchecked") + "' but is '"
                                + (componentStatus ? "checked" : "unchecked") + "'."),
                        SRServices.get(IWritableFactoryManager.class).get(WebDriver.class).newWritable(client));
                error = true;/*from ww w. ja v  a2  s. c  om*/
            }
        } else {
            result.addResult(Failure.INSTANCE, context.peek(),
                    new PluginException("Element " + getFinderInstance().resume(context)
                            + " is not a checkbox or radio is " + element.getTagName()),
                    SRServices.get(IWritableFactoryManager.class).get(WebDriver.class).newWritable(client));
            error = true;
        }
    }
    if (!error) {
        result.addResult(Success.INSTANCE, context.peek());
    }
}

From source file:org.specrunner.webdriver.assertions.PluginSelected.java

License:Open Source License

@Override
protected int checkSelection(IContext context, IResultSet result, WebDriver client, WebElement element)
        throws PluginException {
    Node node = context.getNode();
    Nodes expectedSelection = node.query(getOptionsPath());
    if (expectedSelection.size() == 0) {
        expectedSelection = new Nodes(node);
    }//from  w  w  w  .  j av  a  2s  . c o  m
    List<WebElement> tmp = element.findElements(By.xpath("descendant::option"));
    List<WebElement> currentSelection = new LinkedList<WebElement>();
    for (WebElement we : tmp) {
        if (we.isSelected()) {
            currentSelection.add(we);
        }
    }
    return testList(context, result, client, expectedSelection, currentSelection, false);
}

From source file:org.springside.modules.test.functional.Selenium2.java

License:Apache License

/**
 * ?Element.//w  w w  .j  a  v a  2 s.  com
 */
public void uncheck(By by) {
    WebElement element = driver.findElement(by);
    if (element.isSelected()) {
        element.toggle();
    }
}

From source file:org.sugarcrm.voodoodriver.EventLoop.java

License:Apache License

private WebElement radioEvent(VDDHash event, WebElement parent) {
    boolean required = true;
    boolean click = false;
    WebElement element = null;

    this.report.Log("Radio event starting.");

    if (event.containsKey("required")) {
        required = this.clickToBool(event.get("required").toString());
    }//  w  w w . jav a 2  s.  c  o  m

    try {
        element = this.findElement(event, parent, required);
        if (element == null) {
            this.report.Log("Radio event finished.");
            return element;
        }

        this.firePlugin(element, Elements.RADIO, PluginEvent.AFTERFOUND);

        this.checkDisabled(event, element);

        if (event.containsKey("click")) {
            click = this.clickToBool(event.get("click").toString());
        }

        if (event.containsKey("set")) {
            this.report
                    .Warn("Using the 'set' command for a radio element is not supported anymore!  Use click!");
            click = this.clickToBool(event.get("set").toString());
        }

        String value = element.getAttribute("value");
        handleVars(value, event);

        if (click) {
            this.firePlugin(element, Elements.RADIO, PluginEvent.BEFORECLICK);
            this.report.Log("Clicking Element.");
            element.click();
            this.report.Log("Click finished.");
            this.firePlugin(element, Elements.RADIO, PluginEvent.AFTERCLICK);
        }

        if (event.containsKey("assert")) {
            String src = element.getText();
            String val = this.replaceString(event.get("assert").toString());
            this.report.Assert(val, src);
        }

        if (event.containsKey("assertnot")) {
            String src = element.getText();
            String val = this.replaceString(event.get("assertnot").toString());
            this.report.AssertNot(val, src);
        }

        if (event.containsKey("jscriptevent")) {
            this.report.Log("Firing Javascript Event: " + event.get("jscriptevent").toString());
            this.Browser.fire_event(element, event.get("jscriptevent").toString());
            Thread.sleep(1000);
            this.report.Log("Javascript event finished.");
        }

        if (event.containsKey("checked")) {
            boolean ischecked = element.isSelected();
            boolean expected = this.clickToBool(event.get("checked").toString());
            String msg = "";
            msg = String.format("Radio control's current checked state: '%s', was expecting: '%s'!", ischecked,
                    expected);
            this.report.Assert(msg, ischecked, expected);

        }
    } catch (ElementNotVisibleException exp) {
        logElementNotVisible(required, event);
    } catch (Exception exp) {
        this.report.ReportException(exp);
        element = null;
    }

    this.report.Log("Radio event finished.");
    return element;
}