Example usage for org.openqa.selenium Keys CONTROL

List of usage examples for org.openqa.selenium Keys CONTROL

Introduction

In this page you can find the example usage for org.openqa.selenium Keys CONTROL.

Prototype

Keys CONTROL

To view the source code for org.openqa.selenium Keys CONTROL.

Click Source Link

Usage

From source file:org.richfaces.tests.metamer.ftest.richHotKey.TestHotKeyAttributes.java

License:Open Source License

@Test
public void testPreventDefaultTrue() {
    ATTRIBUTES_FIRST.set(HotKeyAttributes.preventDefault, Boolean.TRUE);
    testKeyForPreventDefault(Keys.chord(Keys.CONTROL, "f"), "ctrl+f", 2);
    testKeyForPreventDefault(Keys.chord(Keys.CONTROL, "h"), "ctrl+h", 2);
    testKeyForPreventDefault(Keys.chord(Keys.CONTROL, "u"), "ctrl+u", 2);
}

From source file:org.richfaces.tests.page.fragments.impl.input.inplaceInput.EditingStateImpl.java

License:Open Source License

private void cancelByKeys() {
    input.sendKeys(Keys.chord(Keys.CONTROL, Keys.ESCAPE));
}

From source file:org.richfaces.tests.page.fragments.impl.input.TextInputComponentImpl.java

License:Open Source License

@Override
public TextInputComponent clear(ClearType clearType) {
    int valueLength = root.getAttribute("value").length();
    Actions builder = new Actions(getWebDriver());
    JavascriptExecutor executor = (JavascriptExecutor) getWebDriver();
    switch (clearType) {
    case BACKSPACE:
        for (int i = 0; i < valueLength; i++) {
            builder.sendKeys(root, Keys.BACK_SPACE);
        }/* w w w .ja v a 2  s.  c  o m*/
        builder.build().perform();
        break;
    case DELETE:
        String ctrlADel = Keys.chord(Keys.CONTROL, "a", Keys.DELETE);
        builder.sendKeys(root, ctrlADel);
        builder.build().perform();
        break;
    case ESCAPE_SQ:
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < valueLength; i++) {
            sb.append("\b");
        }
        root.sendKeys(sb.toString());
        root.click();
        break;
    case JS:
        executor.executeScript("jQuery(arguments[0]).val('')", root);
        break;
    case WD:
        root.clear();
        break;
    default:
        throw new UnsupportedOperationException("Unknown type of clear method " + clearType);
    }
    return this;
}

From source file:org.rstudio.studio.selenium.RConsoleInteraction.java

License:Open Source License

@Test
public void testBasicRInteraction() {
    Actions do42 = new Actions(driver_);
    do42.sendKeys(Keys.chord(Keys.CONTROL, "l"));
    do42.sendKeys(Keys.ESCAPE);
    do42.sendKeys("41 + 1");
    do42.sendKeys(Keys.ENTER);
    do42.perform();

    ConsoleTestUtils.waitForConsoleContainsText(driver_, "42");
}

From source file:org.rstudio.studio.selenium.WorkbenchTests.java

License:Open Source License

@Test
public void testWorkbenchPersistance() throws Exception {
    clearWorkspace();// w  w  w .ja v  a2  s. c o m

    // Add a variable to the workspace
    (new Actions(driver_)).sendKeys(Keys.ESCAPE + "selenium <- function() { 42 }" + Keys.ENTER).perform();

    // Save the workspace 
    WebElement saveItem = MenuNavigator.getMenuItem(driver_, "Session", "Save Workspace As...");
    saveItem.click();

    WebElement saveDialog = DialogTestUtils.waitForModalToAppear(driver_);
    DialogTestUtils.waitForFocusedInput(driver_, saveDialog);

    File tempFile = File.createTempFile("rstudio-selenium-workspace-", ".RData");
    String workspaceFilePath = tempFile.getAbsolutePath();
    tempFile.delete();

    (new Actions(driver_)).sendKeys(workspaceFilePath + Keys.ENTER).perform();

    DialogTestUtils.waitForModalToDisappear(driver_);

    // Clear the workspace and load it again
    clearWorkspace();

    WebElement loadItem = MenuNavigator.getMenuItem(driver_, "Session", "Load Workspace...");
    loadItem.click();

    WebElement loadDialog = DialogTestUtils.waitForModalToAppear(driver_);
    DialogTestUtils.waitForFocusedInput(driver_, loadDialog);

    (new Actions(driver_)).sendKeys(workspaceFilePath + Keys.ENTER).perform();

    DialogTestUtils.waitForModalToDisappear(driver_);

    // List the workspace and see if the variable is present
    ConsoleTestUtils.beginConsoleInteraction(driver_);
    (new Actions(driver_)).sendKeys(Keys.chord(Keys.CONTROL + "l")).sendKeys(Keys.ESCAPE + "ls()" + Keys.ENTER)
            .perform();

    ConsoleTestUtils.waitForConsoleContainsText(driver_, "selenium");
}

From source file:org.safs.selenium.webdriver.CFComponent.java

License:Open Source License

/** <br><em>Purpose:</em> componentClick
 **///from   w w  w  .  j ava  2 s  .co  m
protected void componentClick() throws SAFSException {

    if (compObject == null)
        throw new SAFSException("Component WebElement is null.");

    try {
        java.awt.Point point = checkForCoord(iterator);
        String autoscroll = null;
        if (iterator.hasNext())
            autoscroll = iterator.next();

        long begin = System.currentTimeMillis();
        if (action.equalsIgnoreCase(CLICK) || action.equalsIgnoreCase(COMPONENTCLICK)) {
            if (point == null) {
                WDLibrary.click(compObject, autoscroll);
            } else {
                WDLibrary.click(compObject, point, autoscroll);
            }
        } else if (action.equalsIgnoreCase(DOUBLECLICK)) {
            WDLibrary.doubleClick(compObject, point, autoscroll);
        } else if (action.equalsIgnoreCase(RIGHTCLICK)) {
            WDLibrary.rightclick(compObject, point, autoscroll);
        } else if (action.equalsIgnoreCase(CTRLCLICK)) {
            WDLibrary.click(compObject, point, Keys.CONTROL, WDLibrary.MOUSE_BUTTON_LEFT, autoscroll);
        } else if (action.equalsIgnoreCase(CTRLRIGHTCLICK)) {
            WDLibrary.click(compObject, point, Keys.CONTROL, WDLibrary.MOUSE_BUTTON_RIGHT, autoscroll);
        } else if (action.equalsIgnoreCase(SHIFTCLICK)) {
            WDLibrary.click(compObject, point, Keys.SHIFT, WDLibrary.MOUSE_BUTTON_LEFT, autoscroll);
        }
        long timeConsumed = System.currentTimeMillis() - begin;
        IndependantLog.debug("it took " + timeConsumed + " milliseconds or " + (timeConsumed / 1000)
                + " seconds to perform " + action);

        testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
        String msg = null;
        if (point != null) {
            Log.info("clicking point: " + point);
            String use = "X=" + String.valueOf(point.x) + " Y=" + String.valueOf(point.y);
            altText = windowName + ":" + compName + " " + action + " successful using " + use;
            msg = genericText.convert("success3a", altText, windowName, compName, action, use);
        } else {
            altText = windowName + ":" + compName + " " + action + " successful.";
            msg = genericText.convert("success3", altText, windowName, compName, action);
        }
        log.logMessage(testRecordData.getFac(), msg, PASSED_MESSAGE);

    } catch (Exception e) {
        String errormsg = StringUtils.debugmsg(e);
        IndependantLog.debug(action + " failed. Met Exception " + errormsg);
        issueErrorPerformingActionOnX(compName, errormsg);
    }

}

From source file:org.safs.selenium.webdriver.CFListView.java

License:Open Source License

/**
 * process keywords who need at least one parameter; but it may be supplied with optional parameters.
 * @return boolean true if the keyword has been handled successfully;<br>
 *                 false if the keyword should not be handled in this method.<br>
 * @throws SeleniumPlusException if there are any problem during handling keyword.
 *///from   w  w w. j  a  v  a 2 s.  com
private boolean processWithOneRequiredParameter() throws SAFSException {
    String debugmsg = StringUtils.debugmsg(getClass(), "processWithOneRequiredParameter");
    String requiredParam = (String) iterator.next();
    TextMatchingCriterion criterion = null;

    //Handle optionl parameters
    int matchIndex = 1;
    String encoding = null;
    String variable = null;

    if (action.equalsIgnoreCase(ListViewFunctions.ACTIVATETEXTITEM_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.SELECTTEXTITEM_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.ACTIVATEPARTIALMATCH_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.SELECTPARTIALMATCH_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.ACTIVATEUNVERIFIEDTEXTITEM_KEYWORD)
            //         ||action.equalsIgnoreCase(ListViewFunctions.VERIFYLISTCONTAINS_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.SELECTUNVERIFIEDTEXTITEM_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.RIGHTCLICKTEXTITEM_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.RIGHTCLICKUNVERIFIEDTEXTITEM_KEYWORD)) {

        //'matchIndex' optional parameter
        if (iterator.hasNext()) {
            IndependantLog.info(debugmsg + " command '" + action + "' retrieving optional matchIndex...");
            matchIndex = StringUtilities.getIndex((String) iterator.next());
            IndependantLog.info(debugmsg + " command '" + action + "' matchIndex: " + matchIndex);
        }
    } else if (action.equalsIgnoreCase(ListViewFunctions.CAPTUREITEMSTOFILE_KEYWORD)) {
        //'encoding' optional parameter
        if (iterator.hasNext()) {
            IndependantLog.info(debugmsg + " command '" + action + "' retrieving optional encoding...");
            encoding = (String) iterator.next();
            IndependantLog.info(debugmsg + " command '" + action + "' encoding: " + encoding);
        }

    } else if (action.equalsIgnoreCase(ListViewFunctions.SETLISTCONTAINS_KEYWORD)) {
        //'variable' optional parameter
        if (iterator.hasNext()) {
            IndependantLog.info(debugmsg + " command '" + action + "' retrieving optional variableName...");
            variable = (String) iterator.next();
            IndependantLog.info(debugmsg + " command '" + action + "' variableName: " + variable);
        }

    }

    matchIndex--;//convert 1-based index to 0-based index

    if (action.equalsIgnoreCase(ListViewFunctions.ACTIVATETEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.activateItem(criterion, true, null, null);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.selectItem(criterion, true);

    } else if (action.equalsIgnoreCase(ListViewFunctions.ACTIVATEPARTIALMATCH_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, true, matchIndex);
        listview.activateItem(criterion, false, null, null);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTPARTIALMATCH_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, true, matchIndex);
        listview.selectItem(criterion, false);

    } else if (action.equalsIgnoreCase(ListViewFunctions.ACTIVATEINDEX_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.ACTIVATEINDEXITEM_KEYWORD)) {
        int index = StringUtilities.getIndex(requiredParam);
        listview.activateItem(index, false, null, null);

    } else if (action.equalsIgnoreCase(ListViewFunctions.CLICKINDEX_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.CLICKINDEXITEM_KEYWORD)) {
        int index = StringUtilities.getIndex(requiredParam);
        listview.selectItem(index - 1, false);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTINDEX_KEYWORD)
            || action.equalsIgnoreCase(ListViewFunctions.SELECTINDEXITEM_KEYWORD)) {
        int index = StringUtilities.getIndex(requiredParam);
        listview.selectItem(index - 1, true);

    } else if (action.equalsIgnoreCase(ListViewFunctions.ACTIVATEUNVERIFIEDTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.activateItem(criterion, false, null, null);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTUNVERIFIEDTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.selectItem(criterion, false);

    } else if (action.equalsIgnoreCase(ListViewFunctions.VERIFYITEMUNSELECTED_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false,
                TextMatchingCriterion.INDEX_TRY_ALL_MATCHED_ITEMS);
        listview.verifyItemSelection(criterion, false);

    } else if (action.equalsIgnoreCase(ListViewFunctions.VERIFYLISTCONTAINS_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.verifyContains(criterion);

    } else if (action.equalsIgnoreCase(ListViewFunctions.VERIFYSELECTEDITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false,
                TextMatchingCriterion.INDEX_TRY_ALL_MATCHED_ITEMS);
        listview.verifyItemSelection(criterion, true);

    } else if (action.equalsIgnoreCase(ListViewFunctions.CAPTUREITEMSTOFILE_KEYWORD)) {
        Item[] items = listview.getContent();
        try {
            String filename = deduceTestFile(requiredParam).getAbsolutePath();
            IndependantLog.info(debugmsg + " filename='" + filename + "'; encoding='" + encoding + "'.");
            StringUtils.writeEncodingfile(filename, convertElementArrayToList(items), encoding);
        } catch (IOException e) {
            IndependantLog.error(debugmsg, e);
            throw new SAFSException("Fail to write file due to '" + e.getMessage() + "'");
        }

    } else if (action.equalsIgnoreCase(ListViewFunctions.EXTENDSELECTIONTOTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, true, matchIndex);
        listview.selectItem(criterion, true, Keys.SHIFT, null, WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTANOTHERPARTIALMATCH_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, true, matchIndex);
        listview.selectItem(criterion, true, Keys.CONTROL, null, WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SELECTANOTHERTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.selectItem(criterion, true, Keys.CONTROL, null, WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(ListViewFunctions.SETLISTCONTAINS_KEYWORD)) {
        try {
            criterion = new TextMatchingCriterion(requiredParam, false, 0);
            listview.verifyContains(criterion);
            setVariable(variable, Boolean.toString(true));
        } catch (SeleniumPlusException se) {
            if (!SeleniumPlusException.CODE_VERIFICATION_FAIL.equals(se.getCode()))
                throw se;
            setVariable(variable, Boolean.toString(false));
        }

    } else if (action.equalsIgnoreCase(ListViewFunctions.RIGHTCLICKTEXTITEM_KEYWORD)) {
        //TODO How to verify the right-click???
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.selectItem(criterion, false, null, null, WDLibrary.MOUSE_BUTTON_RIGHT);

    } else if (action.equalsIgnoreCase(ListViewFunctions.RIGHTCLICKUNVERIFIEDTEXTITEM_KEYWORD)) {
        criterion = new TextMatchingCriterion(requiredParam, false, matchIndex);
        listview.selectItem(criterion, false, null, null, WDLibrary.MOUSE_BUTTON_RIGHT);

    } else {
        testRecordData.setStatusCode(StatusCodes.SCRIPT_NOT_EXECUTED);
        IndependantLog.warn(debugmsg + action + " could not be handled here.");
        return false;
    }

    return true;
}

From source file:org.safs.selenium.webdriver.CFTree.java

License:Open Source License

@SuppressWarnings("deprecation")
private boolean processWithOneRequiredParameter() throws SAFSException {
    String debugmsg = StringUtils.debugmsg(getClass(), "processWithOneRequiredParameter");
    String requiredParam = (String) iterator.next();

    //Handle optionl parameters
    int matchIndex = 1;
    String branch = null;/*from  w w w  .j a va 2  s .com*/
    String indentMark = null;
    String encoding = null;

    if (action.equalsIgnoreCase(TreeViewFunctions.CLICKPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.CLICKTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.CLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.COLLAPSE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.COLLAPSEPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.COLLAPSETEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.COLLAPSEUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.CTRLCLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.EXPAND_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.EXPANDPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.EXPANDUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECT_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECTPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECTUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SHIFTCLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.VERIFYNODEUNSELECTED_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.VERIFYSELECTEDNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.VERIFYTREECONTAINSNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.VERIFYTREECONTAINSPARTIALMATCH_KEYWORD)) {

        //'matchIndex' optional parameter
        if (iterator.hasNext())
            matchIndex = StringUtilities.getIndex((String) iterator.next());
    } else if (action.equalsIgnoreCase(TreeViewFunctions.CAPTURETREEDATATOFILE_KEYWORD)) {
        //'encoding' optional parameter
        if (iterator.hasNext())
            branch = (String) iterator.next();
        if (iterator.hasNext())
            indentMark = (String) iterator.next();
        if (iterator.hasNext())
            encoding = (String) iterator.next();
        if (indentMark == null || indentMark.trim().isEmpty())
            indentMark = INDENT_MARK;
    }

    matchIndex--;//convert 1-based index to 0-based index

    if (action.equalsIgnoreCase(TreeViewFunctions.CLICKPARTIAL_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECTPARTIAL_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, true, matchIndex), true, null, null,
                WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.CLICKTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECT_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECTTEXTNODE_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), true, null, null,
                WDLibrary.MOUSE_BUTTON_LEFT);
        //tree.SelectTextNode(requiredParam);//used for keyword SELECTTEXTNODE_KEYWORD

    } else if (action.equalsIgnoreCase(TreeViewFunctions.CLICKUNVERIFIEDTEXTNODE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.SELECTUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, null, null,
                WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.COLLAPSE_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.COLLAPSETEXTNODE_KEYWORD)) {
        tree.collapseItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, true);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.COLLAPSEPARTIAL_KEYWORD)) {
        tree.collapseItem(new TextMatchingCriterion(requiredParam, true, matchIndex), false, true);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.COLLAPSEUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.collapseItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, false);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.CTRLCLICKUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, Keys.CONTROL, null,
                WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKPARTIAL_KEYWORD)) {
        tree.activateItem(new TextMatchingCriterion(requiredParam, true, matchIndex), true, null, null);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKTEXTNODE_KEYWORD)) {
        tree.activateItem(new TextMatchingCriterion(requiredParam, false, matchIndex), true, null, null);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.DOUBLECLICKUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.activateItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, null, null);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.EXPAND_KEYWORD)
            || action.equalsIgnoreCase(TreeViewFunctions.EXPANDTEXTNODE_KEYWORD)) {
        tree.expandItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, true);
        //tree.ExpandTextNode(requiredParam);//used for keyword EXPANDTEXTNODE_KEYWORD

    } else if (action.equalsIgnoreCase(TreeViewFunctions.EXPANDPARTIAL_KEYWORD)) {
        tree.expandItem(new TextMatchingCriterion(requiredParam, true, matchIndex), false, true);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.EXPANDUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.expandItem(new TextMatchingCriterion(requiredParam, true, matchIndex), false, false);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKPARTIAL_KEYWORD)) {
        //         tree.selectItem(new TextMatchingCriterion(requiredParam, true, matchIndex), true, null, null, WDLibrary.MOUSE_BUTTON_RIGHT);
        tree.selectItem(new TextMatchingCriterion(requiredParam, true, matchIndex), false, null, null,
                WDLibrary.MOUSE_BUTTON_RIGHT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKTEXTNODE_KEYWORD)) {
        //         tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), true, null, null, WDLibrary.MOUSE_BUTTON_RIGHT);
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, null, null,
                WDLibrary.MOUSE_BUTTON_RIGHT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.RIGHTCLICKUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, null, null,
                WDLibrary.MOUSE_BUTTON_RIGHT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.SHIFTCLICKUNVERIFIEDTEXTNODE_KEYWORD)) {
        tree.selectItem(new TextMatchingCriterion(requiredParam, false, matchIndex), false, Keys.SHIFT, null,
                WDLibrary.MOUSE_BUTTON_LEFT);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.VERIFYNODEUNSELECTED_KEYWORD)) {
        tree.verifyItemSelection(new TextMatchingCriterion(requiredParam, false, matchIndex), false);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.VERIFYSELECTEDNODE_KEYWORD)) {
        tree.verifyItemSelection(new TextMatchingCriterion(requiredParam, false, matchIndex), true);

    } else if (action.equalsIgnoreCase(TreeViewFunctions.VERIFYTREECONTAINSNODE_KEYWORD)) {
        tree.verifyContains(new TextMatchingCriterion(requiredParam, false, matchIndex));

    } else if (action.equalsIgnoreCase(TreeViewFunctions.VERIFYTREECONTAINSPARTIALMATCH_KEYWORD)) {
        tree.verifyContains(new TextMatchingCriterion(requiredParam, true, matchIndex));

    } else if (action.equalsIgnoreCase(TreeViewFunctions.CAPTURETREEDATATOFILE_KEYWORD)) {
        TreeNode[] contents = null;
        if (branch == null || branch.isEmpty()) {
            contents = tree.getContent();
        } else {
            //if branch contains value, find the correspond node.
            TreeNode node = tree.getMatchedElement(new TextMatchingCriterion(branch, false, 0));
            contents = new TreeNode[1];
            contents[0] = node;
        }

        BufferedWriter writer = null;
        try {
            //requiredParam is filename
            String filename = deduceTestFile(requiredParam).getAbsolutePath();
            writer = FileUtilities.getBufferedFileWriter(filename, encoding);
            writeTreeNodesToFile(writer, contents, indentMark, 0);
        } catch (FileNotFoundException e) {
            throw new SeleniumPlusException("Can not find file '" + requiredParam + "'");
        } finally {
            try {
                if (writer != null)
                    writer.close();
            } catch (IOException ignore) {
            }
        }
    } else {
        testRecordData.setStatusCode(StatusCodes.SCRIPT_NOT_EXECUTED);
        IndependantLog.warn(debugmsg + action + " could not be handled here.");
        return false;
    }

    return true;
}

From source file:org.safs.selenium.webdriver.lib.Component.java

License:Open Source License

/**
 * <em>Purpose:</em> Remove the content from Component Box, like Edit Box, Combo box.<br>
 * //from  w w  w. ja  v  a2  s.  c  o m
 * @param libName String,         the concrete Component name of class, which calls 'clearComponentBox()' method,
 *                             like 'EditBox', 'ComboBox'.
 * 
 */
public void clearComponentBox(String libName) throws SeleniumPlusException {
    String debugmsg = getClass().getName() + ".clearComponentBox(): ";

    try {
        try {
            // chrome and ie are failing element.clear
            webelement.clear();
        } catch (StaleElementReferenceException sere) {
            IndependantLog.warn(debugmsg + "Met " + StringUtils.debugmsg(sere));
            //fresh the element and clear again.
            refresh(false);
            webelement.clear();
        }
        //Selenium API clear() will sometimes redraw the Web Element on the page,
        //which will cause StaleElementReferenceException, we need to refresh it if stale
        refresh(true);
    } catch (NoSuchElementException msee) {
        IndependantLog.debug(debugmsg + "NoSuchElementException --Object not found.");
        throw new SeleniumPlusException(libName + " object not found");

    } catch (Exception e) {
        IndependantLog.debug(debugmsg + "Met " + StringUtils.debugmsg(e));
        try {
            refresh(true);
            webelement.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.DELETE);
        } catch (Exception x) {
            IndependantLog.debug(debugmsg + "Met " + StringUtils.debugmsg(x));
            try {
                refresh(true);
                Actions delete = new Actions(WDLibrary.getWebDriver());
                delete.sendKeys(webelement, Keys.chord(Keys.CONTROL, "a"), Keys.DELETE);
                delete.perform();
            } catch (Exception ex) {
                IndependantLog
                        .warn(debugmsg + libName + " clear action failed, Met " + StringUtils.debugmsg(ex));
            }
        }
    } finally {
        IndependantLog.debug(debugmsg + "Finally use SAFS Robot to clear again.");
        WDLibrary.inputKeys(webelement, "^a{Delete}");
    }
}

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

License:Open Source License

@Override
protected boolean performSelect(WebElement select, WebElement option, TestRun ctx) {
    try {//  www .  j  a  v  a2 s  .  c om
        Actions action = new Actions(ctx.driver());
        action.keyDown(Keys.CONTROL);
        action.perform();

        option.click();

        action = new Actions(ctx.driver());
        action.keyUp(Keys.CONTROL);
        action.perform();
        return true;
    } catch (Exception x) {
        ctx.log().error("Select Option CTRL+click " + x.getClass().getSimpleName() + ", " + x.getMessage());
        return false;
    }
}