org.openqa.selenium.Keys Java Examples

The following examples show how to use org.openqa.selenium.Keys. 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: HTMLInputElementTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void typeMaxLength() throws Exception {
    final String html
        = HtmlPageTest.STANDARDS_MODE_PREFIX_
        + "<html><body>\n"
        + "<form>\n"
        + "<input type='text' id='text1' maxlength='5'/>\n"
        + "<input type='password' id='password1' maxlength='6'/>\n"
        + "</form></body></html>";

    final WebDriver webDriver = loadPage2(html);
    final WebElement textField = webDriver.findElement(By.id("text1"));
    textField.sendKeys("123456789");
    assertEquals("12345", textField.getAttribute("value"));
    textField.sendKeys(Keys.BACK_SPACE);
    textField.sendKeys("7");
    assertEquals("12347", textField.getAttribute("value"));

    final WebElement passwordField = webDriver.findElement(By.id("password1"));
    passwordField.sendKeys("123456789");
    assertEquals("123456", passwordField.getAttribute("value"));
    passwordField.sendKeys(Keys.BACK_SPACE);
    passwordField.sendKeys("7");
    assertEquals("123457", passwordField.getAttribute("value"));
}
 
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: DataGridImpl.java    From masquerade with Apache License 2.0 6 votes vote down vote up
@Override
public SelenideElement deselectRow(By rowBy) {
    this.shouldBe(VISIBLE)
            .shouldBe(ENABLED);

    SelenideElement row = getRow(rowBy)
            .shouldBe(visible)
            .shouldHave(selectedClass);

    WebDriver webDriver = WebDriverRunner.getWebDriver();
    Actions action = new Actions(webDriver);

    Keys controlKey = getControlKey();

    action.keyDown(controlKey)
            .click(row.getWrappedElement())
            .keyUp(controlKey)
            .build()
            .perform();

    return row;
}
 
Example #4
Source File: JMenuTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void menuItemShortcuts() throws Throwable {
    // This test for testing keyboard shortcuts on menu items need to be
    // fixed after the bug fix in send keys.
    driver = new JavaDriver();
    WebElement textArea = driver.findElement(By.cssSelector("text-area"));
    textArea.click();

    textArea.sendKeys(Keys.chord(Keys.ALT, "1"));
    AssertJUnit.assertTrue(
            "Error:Expected to end with:\n" + "Event source: A text-only menu item (an instance of JMenuItem)\n" + "\nActual:\n"
                    + textArea.getText().trim(),
            textArea.getText().trim().endsWith("Event source: A text-only menu item (an instance of JMenuItem)\n".trim()));
    textArea.sendKeys(Keys.chord(Keys.ALT, "2"));
    AssertJUnit.assertTrue(
            "Error:Expected to end with:\n" + "Event source: A text-only menu item (an instance of JMenuItem)\n" + "\nActual:\n"
                    + textArea.getText().trim(),
            textArea.getText().trim().endsWith("Event source: An item in the submenu (an instance of JMenuItem)\n".trim()));
}
 
Example #5
Source File: DomElementTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception on test failure
 */
@Test
public void sendEnterKey() throws Exception {
    final String html = "<!DOCTYPE html>\n"
        + "<html><head></head>\n"
        + "<body>\n"
        + "  <form id='myForm' action='" + URL_SECOND + "'>\n"
        + "    <input id='myText' type='text'>\n"
        + "  </form>\n"
        + "</body></html>";
    final String secondContent = "second content";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myText")).sendKeys(Keys.ENTER);

    assertEquals(2, getMockWebConnection().getRequestCount());
    assertEquals(URL_SECOND, getMockWebConnection().getLastWebRequest().getUrl());
}
 
Example #6
Source File: AaarghFirefoxWhyDostThouMockMe.java    From webDriverExperiments with MIT License 6 votes vote down vote up
private void checkSimpleCtrlBInteractionWorks() {

        driver.get(KEY_CLICK_DISPLAY);

        new Actions(driver).keyDown(Keys.CONTROL).
                sendKeys("b").
                keyUp(Keys.CONTROL).
                perform();

        System.out.println(driver.findElement(By.id("events")).getText());

        assertEquals( "only expected 4 events",
                      4,
                      driver.findElements(
                            By.cssSelector("#events p")).size());
    }
 
Example #7
Source File: FrontEndTests.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void completionApplyCaretPosition() throws InterruptedException {
    driver.navigate().to(url);

    // Start the add-in
    driver.findElement(By.id("startButton")).click();

    driver.findElement(By.id("genconfURI")).sendKeys(genconfURI);
    driver.findElement(By.id("expression")).click();
    driver.findElement(By.id("expression")).sendKeys("self.ances");
    Thread.sleep(2000);
    driver.findElement(By.id("expression")).sendKeys("t");
    Thread.sleep(1000);

    driver.findElement(By.id("expression")).sendKeys(Keys.DOWN);
    driver.findElement(By.id("expression")).sendKeys(Keys.ENTER);
    Thread.sleep(1000);
    assertEquals("self.ancestors()", driver.findElement(By.id("expression")).getAttribute("value"));
    assertEquals("15", driver.findElement(By.id("expression")).getAttribute("selectionStart"));
    assertEquals("15", driver.findElement(By.id("expression")).getAttribute("selectionEnd"));
}
 
Example #8
Source File: CombinedInputActionsTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore(IE)
@NotYetImplemented(SAFARI)
public void testCombiningShiftAndClickResultsInANewWindow() {
  driver.get(pages.linkedImage);
  WebElement link = driver.findElement(By.id("link"));
  String originalTitle = driver.getTitle();

  int nWindows = driver.getWindowHandles().size();
  new Actions(driver)
      .moveToElement(link)
      .keyDown(Keys.SHIFT)
      .click()
      .keyUp(Keys.SHIFT)
      .perform();

  wait.until(windowHandleCountToBe(nWindows + 1));
  assertThat(driver.getTitle())
      .describedAs("Should not have navigated away").isEqualTo(originalTitle);
}
 
Example #9
Source File: CheTerminal.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * scroll terminal by pressing key 'End'
 *
 * @param item is the name of the highlighted item
 */
public void moveDownListTerminal(String item) {
  loader.waitOnClosed();
  typeIntoActiveTerminal(Keys.END.toString());
  WaitUtils.sleepQuietly(2);

  WebElement element =
      seleniumWebDriver.findElement(
          By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item)));

  if (!element.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN)) {
    typeIntoActiveTerminal(Keys.ARROW_UP.toString());
    element =
        seleniumWebDriver.findElement(
            By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item)));
    WaitUtils.sleepQuietly(2);
  }
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(visibilityOf(element));
  WebElement finalElement = element;
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          (WebDriver input) ->
              finalElement.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN));
}
 
Example #10
Source File: SynchronizedPropertyIT.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeInitialValueNotSentToServer() {
    open();
    WebElement syncOnChangeInitialValue = findElement(
            By.id("syncOnChangeInitialValue"));
    WebElement labelSyncOnChange = findElement(
            By.id("syncOnChangeInitialValueLabel"));

    // Property was set after label was created and sync set up
    // It is intentionally in the "wrong" state until there is a sync
    // message from the client
    Assert.assertEquals("Server value on create: null",
            labelSyncOnChange.getText());
    syncOnChangeInitialValue.sendKeys(Keys.END);
    syncOnChangeInitialValue.sendKeys("123");
    blur();
    Assert.assertEquals("Server value in change listener: initial123",
            labelSyncOnChange.getText());

}
 
Example #11
Source File: HtmlPasswordInputTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void type() throws Exception {
    final String html = "<html><head></head><body><input type='password' id='p'/></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement p = driver.findElement(By.id("p"));
    p.sendKeys("abc");
    assertEquals("abc", p.getAttribute("value"));
    p.sendKeys(Keys.BACK_SPACE);
    assertEquals("ab", p.getAttribute("value"));
    p.sendKeys(Keys.BACK_SPACE);
    assertEquals("a", p.getAttribute("value"));
    p.sendKeys(Keys.BACK_SPACE);
    assertEquals("", p.getAttribute("value"));
    p.sendKeys(Keys.BACK_SPACE);
    assertEquals("", p.getAttribute("value"));
}
 
Example #12
Source File: HtmlSearchInputTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void type() throws Exception {
    final String html = "<html><head></head><body><input id='t' type='search'/></body></html>";

    final WebDriver webDriver = loadPage2(html);
    final WebElement input = webDriver.findElement(By.id("t"));
    input.sendKeys("abc");
    assertEquals("abc", input.getAttribute("value"));
    input.sendKeys(Keys.BACK_SPACE);
    assertEquals("ab", input.getAttribute("value"));
    input.sendKeys(Keys.BACK_SPACE);
    assertEquals("a", input.getAttribute("value"));
    input.sendKeys(Keys.BACK_SPACE);
    assertEquals("", input.getAttribute("value"));
    input.sendKeys(Keys.BACK_SPACE);
    assertEquals("", input.getAttribute("value"));
}
 
Example #13
Source File: JButtonTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("Disable middle button", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("Middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("Enable middle button", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
 
Example #14
Source File: BasicKeyboardInterfaceTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(EDGE)
public void testSendingKeysWithShiftPressed() {
  driver.get(pages.javascriptPage);

  WebElement keysEventInput = driver.findElement(By.id("theworks"));

  keysEventInput.click();

  String existingResult = getFormEvents();

  Action pressShift = getBuilder(driver).keyDown(keysEventInput, Keys.SHIFT).build();
  pressShift.perform();

  Action sendLowercase = getBuilder(driver).sendKeys(keysEventInput, "ab").build();
  sendLowercase.perform();

  Action releaseShift = getBuilder(driver).keyUp(keysEventInput, Keys.SHIFT).build();
  releaseShift.perform();

  String expectedEvents = " keydown keydown keypress keyup keydown keypress keyup keyup";
  assertThatFormEventsFiredAreExactly("Shift key not held", existingResult + expectedEvents);

  assertThat(keysEventInput.getAttribute("value")).isEqualTo("AB");
}
 
Example #15
Source File: SeleniumTests.java    From demo with MIT License 6 votes vote down vote up
/**
 * In this case, we have one book and one borrower,
 * so we should get a dropdown
 *
 * more detail:
 * Under lending, books and borrowers inputs have three modes.
 * a) if no books/borrowers, lock the input
 * b) If 1 - 9, show a dropdown
 * c) If 10 and up, show an autocomplete
 */
@Test
public void test_shouldShowDropdowns() {
    // clear the database...
    driver.get("http://localhost:8080/demo/flyway");
    ApiCalls.registerBook("some book");
    ApiCalls.registerBorrowers("some borrower");

    driver.get("http://localhost:8080/demo/library.html");

    // using the arrow keys to select an element is a very "dropdown" kind of behavior.
    driver.findElement(By.id("lend_book")).sendKeys(Keys.ARROW_UP);
    driver.findElement(By.id("lend_borrower")).sendKeys(Keys.ARROW_UP);
    driver.findElement(By.id("lend_book_submit")).click();
    final String result = driver.findElement(By.id("result")).getText();
    assertEquals("SUCCESS", result);
}
 
Example #16
Source File: KeyEventSetpDefinitions.java    From IridiumApplicationTesting with MIT License 6 votes vote down vote up
/**
 * Press the delete key on the active element. This step is known to have issues with
 * the Firefox Marionette driver.
 * @param times The number of times to press the delete key
 * @param ignoreErrors Add this text to ignore any exceptions. This is really only useful for debugging.
 */
@When("^I press(?: the)? Delete(?: key)? on the active element(?: \"(\\d+)\" times)?( ignoring errors)?$")
public void pressDeleteStep(final Integer times, final String ignoreErrors) {
	try {
		final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread();
		final WebElement element = webDriver.switchTo().activeElement();

		for (int i = 0; i < ObjectUtils.defaultIfNull(times, 1); ++i) {
			element.sendKeys(Keys.DELETE);
			sleepUtils.sleep(State.getFeatureStateForThread().getDefaultKeyStrokeDelay());
		}

		sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep());
	} catch (final Exception ex) {
		if (StringUtils.isBlank(ignoreErrors)) {
			throw ex;
		}
	}
}
 
Example #17
Source File: TypingTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * A test.
 */
@Test
public void deleteAndBackspaceKeys() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys("abcdefghi");
    assertThat(element.getAttribute("value"), is("abcdefghi"));

    element.sendKeys(Keys.LEFT, Keys.LEFT, Keys.DELETE);
    assertThat(element.getAttribute("value"), is("abcdefgi"));

    element.sendKeys(Keys.LEFT, Keys.LEFT, Keys.BACK_SPACE);
    assertThat(element.getAttribute("value"), is("abcdfgi"));
}
 
Example #18
Source File: TwoWayListBindingIT.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void itemsInList_twoWayDataBinding_updatesAreSentToServer() {
    open();

    findElement(By.id("enable")).click();

    List<WebElement> fields = $("two-way-list-binding").first()
            .$(DivElement.class).first().findElements(By.id("input"));

    // self check
    Assert.assertEquals(2, fields.size());

    fields.get(0).clear();
    fields.get(0).sendKeys("baz");
    fields.get(0).sendKeys(Keys.TAB);

    Assert.assertEquals("[baz, bar]", getLastInfoMessage());

    fields.get(1).sendKeys("foo");
    fields.get(1).sendKeys(Keys.TAB);

    Assert.assertEquals("[baz, barfoo]", getLastInfoMessage());
}
 
Example #19
Source File: ShortcutsIT.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void listenOnScopesTheShortcut() {
    sendKeys(Keys.ALT, "s");
    assertActualEquals(DEFAULT_VALUE); // nothing happened

    WebElement innerInput = findElement(By.id("focusTarget"));
    innerInput.sendKeys(Keys.ALT, "s");
    assertActualEquals("subview");

    // using the shortcut prevented "s" from being written
    Assert.assertEquals("", innerInput.getText());
}
 
Example #20
Source File: TheInternetExampleTests.java    From frameworkium-examples with Apache License 2.0 5 votes vote down vote up
@TmsLink("INT-12")
public void key_presses() {

    // Navigate to the key presses page
    var keyPressesPage = WelcomePage
            .open()
            .clickKeyPressesLink()
            .enterKeyPress(Keys.ENTER);

    assertThat(keyPressesPage.getResultText())
            .isEqualTo("You entered: " + Keys.ENTER.name());
}
 
Example #21
Source File: CheTerminal.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * scroll terminal by pressing key 'PageUp'
 *
 * @param item is the name of the highlighted item
 */
public void movePageUpListTerminal(String item) {
  loader.waitOnClosed();
  typeIntoActiveTerminal(Keys.PAGE_UP.toString());
  WaitUtils.sleepQuietly(2);
  WebElement element =
      seleniumWebDriver.findElement(
          By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item)));
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(visibilityOf(element));
  new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
      .until(
          (WebDriver input) ->
              element.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN));
}
 
Example #22
Source File: LibraryControlCheckboxDefaultAft.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void testCheckboxControlDisableWhenChanged() throws Exception {
        navigateToExample("Demo-CheckboxControl-Example9");

        waitForElementPresentById("ST-DemoCheckboxControlExample9-Input1_control");
        waitForElementPresentById("ST-DemoCheckboxControlExample9-Input2_control");
        assertTextPresent("Specifies the property names of fields that when changed, will disable this component");

        // check that checkbox controls is visible, not selected and enabled
        assertTrue(isVisibleById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertFalse(isCheckedById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertTrue(isEnabledById("ST-DemoCheckboxControlExample9-Input2_control"));

        // backspace input1 and remove focus from input1 (by doing an arrow down on the checkbox)
        driver.findElement(By.id("ST-DemoCheckboxControlExample9-Input1_control")).sendKeys(Keys.BACK_SPACE);
        // chrome is giving a WebDriverException: unknown error: cannot focus element error here, when not using Actions
//        driver.findElement(By.id("Demo-CheckboxControl-Example9")).sendKeys(Keys.ARROW_DOWN);
        actionSendKeysArrowDown("ST-DemoCheckboxControlExample9-Input1_control");

        // check that checkbox controls is visible, not selected and enabled
        assertTrue(isVisibleById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertFalse(isCheckedById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertTrue(isEnabledById("ST-DemoCheckboxControlExample9-Input2_control"));

        // type "Hello" in input1 and remove focus from input1 (by doing an arrow down on the checkbox)
        driver.findElement(By.id("ST-DemoCheckboxControlExample9-Input1_control")).sendKeys("Hello");
        // chrome is giving a WebDriverException: unknown error: cannot focus element error here, when not using Actions
//        driver.findElement(By.id("Demo-CheckboxControl-Example9")).sendKeys(Keys.ARROW_DOWN);
        actionSendKeysArrowDown("Demo-CheckboxControl-Example9");

        // check that checkbox controls is visible, not selected and disabled
        assertTrue(isVisibleById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertFalse(isCheckedById("ST-DemoCheckboxControlExample9-Input2_control"));
        assertFalse(isEnabledById("ST-DemoCheckboxControlExample9-Input2_control"));
    }
 
Example #23
Source File: TypingTest.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if an error occurs
 */
@Test
public void shouldBeAbleToUseArrowKeys() throws Exception {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement keyReporter = driver.findElement(By.id("keyReporter"));
    keyReporter.sendKeys("tet", Keys.ARROW_LEFT, "s");

    assertThat(keyReporter.getAttribute("value"), is("test"));
}
 
Example #24
Source File: CucumberTypeRegistryConfigurer.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
private static String getAllKeys() {
    StringBuilder sb = new StringBuilder();
    for (Keys kk : Keys.values()) {
        sb.append(kk.name()).append("|");
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}
 
Example #25
Source File: SeleniumTests.java    From demo with MIT License 5 votes vote down vote up
/**
 * In this case, we have 10 books and one borrower,
 * so we should get a autocomplete for books
 *
 * more detail:
 * Under lending, books and borrowers inputs have three modes.
 * a) if no books/borrowers, lock the input
 * b) If 1 - 9, show a dropdown
 * c) If 10 and up, show an autocomplete
 */
@Test
public void test_shouldShowAutocomplete() {
    // clear the database...
    driver.get("http://localhost:8080/demo/flyway");
    ApiCalls.registerBook("a");
    ApiCalls.registerBook("b");
    ApiCalls.registerBook("c");
    ApiCalls.registerBook("d");
    ApiCalls.registerBook("e");
    ApiCalls.registerBook("f");
    ApiCalls.registerBook("g");
    ApiCalls.registerBook("h");
    ApiCalls.registerBook("i");
    ApiCalls.registerBook("j");
    ApiCalls.registerBorrowers("some borrower");

    driver.get("http://localhost:8080/demo/library.html");

    // using the arrow keys to select an element is a very "dropdown" kind of behavior.
    driver.findElement(By.id("lend_book")).sendKeys("f");
    driver.findElement(By.xpath("//li[contains(.,\'f\')]")).click();
    driver.findElement(By.id("lend_borrower")).sendKeys(Keys.ARROW_UP);
    driver.findElement(By.id("lend_book_submit")).click();
    final String result = driver.findElement(By.id("result")).getText();
    assertEquals("SUCCESS", result);
}
 
Example #26
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 #27
Source File: DateTimeFieldImpl.java    From masquerade with Apache License 2.0 5 votes vote down vote up
@Override
public DateTimeField setTimeValue(String value) {
    SelenideElement timeFieldImpl = $(byChain(by, TIMEPART));

    timeFieldImpl
            .shouldBe(visible)
            .shouldBe(enabled)
            .shouldNotBe(readonly)
            .click();

    timeFieldImpl.sendKeys(Keys.HOME, value);
    return this;
}
 
Example #28
Source File: WebTestIOS.java    From samples with MIT License 5 votes vote down vote up
@Test(description = "should run test successfully with correct username and password")
public void testLoginSuccessfully() {
    driver.get("http://google.com");
    WebElement searchFieldE = driver.findElementByXPath("//input[@name='q']");
    searchFieldE.sendKeys("Kobiton");
    searchFieldE.sendKeys(Keys.ENTER);
    driver.findElementByXPath("//a[@href='https://kobiton.com/']").click();
    String message = driver.findElementByXPath("//div[@class='intro-message']/h2").getText();

    Assert.assertTrue(message.contains("Real Devices in the Cloud, Better Testing for You"));
}
 
Example #29
Source File: GoogleLogin.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** type into password field on Google authorization page user - defined password */
public void typePasswordDefinedByUser(String password) {
  new WebDriverWait(seleniumWebDriver, 10)
      .until(ExpectedConditions.visibilityOf(passwordInput))
      .sendKeys(password);
  passwordInput.sendKeys(Keys.ENTER.toString());
}
 
Example #30
Source File: RoundUpSteps.java    From akita with Apache License 2.0 5 votes vote down vote up
private CharSequence getKeyOrCharacter(String key) {
    try {
        return Keys.valueOf(key.toUpperCase());
    } catch (IllegalArgumentException ex) {
        return key;
    }
}