Java Code Examples for org.openqa.selenium.Keys#CONTROL

The following examples show how to use org.openqa.selenium.Keys#CONTROL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragAndDropTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.getCurrent().is(Platform.WINDOWS)) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
Example 2
Source File: DataGridImpl.java    From masquerade with Apache License 2.0 6 votes vote down vote up
/**
 * @return control key depending on operating system
 */
protected Keys getControlKey() {
    Keys controlKey = Keys.CONTROL;

    WebDriver webDriver = WebDriverRunner.getWebDriver();
    if (webDriver instanceof JavascriptExecutor) {
        // check if working on MacOS
        Object result = ((JavascriptExecutor) webDriver)
                .executeScript("return window.navigator.platform");

        if (result instanceof String) {
            String platform = (String) result;

            if (MAC_OS_PLATFORM.equals(platform)) {
                controlKey = Keys.COMMAND;
            }
        }
    }

    return controlKey;
}
 
Example 3
Source File: TableImpl.java    From masquerade with Apache License 2.0 6 votes vote down vote up
/**
 * @return control key depending on operating system
 */
protected Keys getControlKey() {
    Keys controlKey = Keys.CONTROL;

    WebDriver webDriver = WebDriverRunner.getWebDriver();
    if (webDriver instanceof JavascriptExecutor) {
        // check if working on MacOS
        Object result = ((JavascriptExecutor) webDriver)
                .executeScript("return window.navigator.platform");

        if (result instanceof String) {
            String platform = (String) result;

            if (MAC_OS_PLATFORM.equals(platform)) {
                controlKey = Keys.COMMAND;
            }
        }
    }

    return controlKey;
}
 
Example 4
Source File: Utils.java    From SWET with MIT License 6 votes vote down vote up
public void inspectElement(WebElement element) {
	keyCTRL = osName.startsWith("mac") ? Keys.COMMAND : Keys.CONTROL;

	if (osName.startsWith("mac")) {
		actions.keyDown(keyCTRL).build().perform();
		actions.moveToElement(element).contextClick().build().perform();
		actions.keyUp(keyCTRL).build().perform();
	} else {
		actions.moveToElement(element).build().perform();
		actions.keyDown(keyCTRL).contextClick().keyUp(keyCTRL).build().perform();
	}
	// Assert
	try {
		Thread.sleep(100);
	} catch (InterruptedException e) {
	}
}
 
Example 5
Source File: OSUtils.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Keys getMenuKey() {
    int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    if (keyMask == Event.CTRL_MASK) {
        return Keys.CONTROL;
    }
    if (keyMask == Event.META_MASK) {
        return Keys.META;
    }
    if (keyMask == Event.ALT_MASK) {
        return Keys.ALT;
    }
    throw new WebDriverException("Unable to find the keymask... not control or meta?");
}
 
Example 6
Source File: JListXTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void listMultipleSelectWithControl() throws Throwable {
    driver = new JavaDriver();
    WebElement listItem;
    listItem = driver.findElement(By.cssSelector("#list-1::nth-item(6)"));
    WebElement listItem2 = driver.findElement(By.cssSelector("#list-1::nth-item(3)"));
    WebElement listItem3 = driver.findElement(By.cssSelector("#list-1::nth-item(4)"));
    Keys command = Platform.getCurrent().is(Platform.MAC) ? Keys.COMMAND : Keys.CONTROL;
    new Actions(driver).click(listItem).sendKeys(command).click(listItem2).click(listItem3).sendKeys(command).perform();
    ArrayList<Integer> al = new ArrayList<Integer>();
    int[] selectedIndices = new int[] { 2, 3, 5 };
    for (int i : selectedIndices) {
        al.add(i);
    }
    assertEquals(al.toString(), driver.findElement(By.cssSelector("#list-1")).getAttribute("selectedIndices"));
}
 
Example 7
Source File: CommonMethods.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
Keys getKeyCode(String data) {
    switch (data) {
        case "tab":
            return Keys.TAB;
        case "enter":
            return Keys.ENTER;
        case "shift":
            return Keys.SHIFT;
        case "ctrl":
            return Keys.CONTROL;
        case "alt":
            return Keys.ALT;
        case "esc":
            return Keys.ESCAPE;
        case "delete":
            return Keys.DELETE;
        case "backspace":
            return Keys.BACK_SPACE;
        case "home":
            return Keys.HOME;
        default:
            try {
                return Keys.valueOf(data.toUpperCase());
            } catch (Exception ex) {
                return null;
            }
    }
}
 
Example 8
Source File: AdfTable.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
public void selectAdditionalRow(int index) {
    scrollToRowIndex(index);
    WebElement row = findRow(index);
    final Keys key = isPlatform(Platform.MAC) ? Keys.COMMAND : Keys.CONTROL;
    new Actions(getDriver()).keyDown(key).click(row).keyUp(key).perform();
    waitForPpr();
}
 
Example 9
Source File: IndividualKeyboardActionsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void keyUpActionWithoutProvidedElement() {
  final Keys keyToRelease = Keys.CONTROL;

  KeyUpAction keyUp = new KeyUpAction(mockKeyboard, mockMouse, keyToRelease);
  keyUp.perform();

  InOrder order = Mockito.inOrder(mockKeyboard, mockMouse, mockCoordinates);
  order.verify(mockKeyboard).releaseKey(keyToRelease);
  order.verifyNoMoreInteractions();
}
 
Example 10
Source File: IndividualKeyboardActionsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllModifierKeysRegardedAsSuch() {
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.SHIFT);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.LEFT_SHIFT);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.CONTROL);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.LEFT_CONTROL);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.ALT);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.LEFT_ALT);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.META);
  new KeyDownAction(mockKeyboard, mockMouse, stubLocatable, Keys.COMMAND);
}
 
Example 11
Source File: CodeEditorHandlerThread.java    From collect-earth with MIT License 5 votes vote down vote up
private void sendThroughClipboard(WebElement textArea, String contents) {
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection clipboardtext = new StringSelection(contents);
	clipboard.setContents(clipboardtext, null);
	Keys controlChar = Keys.CONTROL;
	if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
		controlChar = Keys.COMMAND;
	}
	textArea.sendKeys(Keys.chord(controlChar, "a"));
	textArea.sendKeys(Keys.chord(controlChar, "v"));
}
 
Example 12
Source File: BrowserTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
protected Keys controlKey() {
    return sendCommandForControlOnMac ? getSeleniumHelper().getControlOrCommand() : Keys.CONTROL;
}
 
Example 13
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
/**
 * @return Keys#COMMAND if the browser is running on a Mac, or Keys#CONTROL otherwise.
 */
public Keys getControlOrCommand() {
    return connectedToMac() ? Keys.COMMAND : Keys.CONTROL;
}
 
Example 14
Source File: CodeEditorHandlerThread.java    From collect-earth with MIT License 4 votes vote down vote up
private void sendThroughKeys(WebElement textArea, String contents)
			throws InterruptedException {
		// Command key (apple key) is not working on Chrome on Mac. Try with the right click
		// This is not going to be fixed by Selenium
		
		// Remove comments so it is faster to send the text!
		String noComments = removeComments(contents);

		// Clear the code area
		WebElement clearButton = webDriverGee.findElementByCssSelector(RESET_SCRIPT_BUTTON);
		forceClick( clearButton );

		StringBuilder fixedScriptForMac = new StringBuilder();
		String[] lines = noComments.split("\\n");
		for (String line : lines) {
			// Send the content of the script
			String trimmedLine = line.trim();

			// Add Spaces after "{" so we avoid the automatic closing of the method by GEE
			// Playground JS
			trimmedLine = trimmedLine.replace("{", "{ ");

			if (!StringUtils.isBlank(trimmedLine)) {
				fixedScriptForMac = fixedScriptForMac.append(trimmedLine).append("\n");
			}
		}

		fixedScriptForMac.append("//THE END"); // Don't remove this!!! this way we mark the point where there should be no trailing character removal
		Keys controlChar = Keys.CONTROL;
		if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
			controlChar = Keys.COMMAND;
		}
		textArea.sendKeys(Keys.chord(controlChar, "a"));
		textArea.sendKeys(fixedScriptForMac);
/*
		Thread.sleep(500);
		// Fix the extra characters added by removing the last 10 chars ( this is a bug from Selenium! )
		textArea.sendKeys(Keys.PAGE_DOWN);
		Thread.sleep(500);
		textArea.sendKeys(Keys.PAGE_DOWN);
		*/
	}