List of usage examples for org.openqa.selenium Keys LEFT
Keys LEFT
To view the source code for org.openqa.selenium Keys LEFT.
Click Source Link
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./*from www .j a va 2 s.c om*/ */ @Test public void testArrowKeysAndPageUpAndDown() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys( "a" + Keys.LEFT + "b" + Keys.RIGHT + Keys.UP + Keys.DOWN + Keys.PAGE_UP + Keys.PAGE_DOWN + "1"); assertThat(element.getAttribute("value"), is("ba1")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//from w w w. java 2 s. c o m */ @Test public void homeAndEndAndPageUpAndPageDownKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("abc" + Keys.HOME + "0" + Keys.LEFT + Keys.RIGHT + Keys.PAGE_UP + Keys.PAGE_DOWN + Keys.END + "1" + Keys.HOME + "0" + Keys.PAGE_UP + Keys.END + "111" + Keys.HOME + "00"); assertThat(element.getAttribute("value"), is("0000abc1111")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//from ww w .jav a 2 s . c o m */ @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")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//ww w .jav a2 s.co m */ @Test public void shiftSelectionDeletes() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("abcd efgh"); assertThat(element.getAttribute("value"), is("abcd efgh")); element.sendKeys(Keys.SHIFT, Keys.LEFT, Keys.LEFT, Keys.LEFT); element.sendKeys(Keys.DELETE); assertThat(element.getAttribute("value"), is("abcd e")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.// ww w.j a v a 2 s.c o m */ @Test public void nonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() { final WebDriver driver = getWebDriver("/rich_text.html"); driver.switchTo().frame("editFrame"); final WebElement element = driver.switchTo().activeElement(); element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT); element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!"); assertEquals("Fishee!", element.getText()); }
From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextDefaultValueTester.java
License:Open Source License
@Test public void runInputRichTextGeneralTest() { // 1. Navigate to the "inputRichText" "Default Value" use case. BrowserDriver browserDriver = getBrowserDriver(); navigateToUseCase(browserDriver, "inputRichText", "default-value"); // 2. Verify that "<p>This is some <strong>bold</strong> text<br />\nand this is some <em>italic</em> text.</p>" // appears in the *Model Value*. WaitingAsserter waitingAsserter = getWaitingAsserter(); waitingAsserter.assertTextPresentInElement( "<p>This is some <strong>bold</strong> text<br />\nand this is some <em>italic</em> text.</p>", modelValue1Xpath);//from w w w .ja v a2 s . com // 3. Before the text "ld text and this is some italic text.", type "ld o". browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH); Actions insertText = browserDriver.createActions(BODY_XPATH); WebElement body = browserDriver.findElementByXpath(BODY_XPATH); insertText.click(body); for (int i = 0; i < "ld text and this is some italic text.".length(); i++) { insertText.sendKeys(Keys.LEFT); } insertText.perform(); browserDriver.sendKeysToElement(BODY_XPATH, "ld o"); // 4. Click the *Submit* button. String expectedText = "<p>This is some <strong>bold old</strong> text<br />\nand this is some <em>italic</em> text.</p>"; submitRichText(browserDriver, submitButton1Xpath, 1, expectedText); //J- // 5. Verify that // "<p>This is some <strong>bold old</strong> text<br />\nand this is some <em>italic</em> text.</p>" appears in // the *Model Value*. //J+ waitingAsserter.assertTextPresentInElement(expectedText, modelValue1Xpath); }
From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java
License:Open Source License
protected static void selectTextAndSendKeys(BrowserDriver browserDriver, String completeText, String textToSelect, CharSequence... keys) { if (!completeText.contains(textToSelect)) { throw new IllegalArgumentException( "\"" + completeText + "\" does not contain \"" + textToSelect + "\""); }/*from w ww. j a v a 2 s. c om*/ Actions boldAndItalicize = browserDriver.createActions(BODY_XPATH); WebElement body = browserDriver.findElementByXpath(BODY_XPATH); boldAndItalicize.click(body); for (int i = 0; i < completeText.length(); i++) { boldAndItalicize.sendKeys(Keys.LEFT); } int beginIndex = completeText.indexOf(textToSelect); for (int i = 0; i < beginIndex; i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyDown(Keys.SHIFT); for (int i = 0; i < textToSelect.length(); i++) { boldAndItalicize.sendKeys(Keys.RIGHT); } boldAndItalicize.keyUp(Keys.SHIFT); boldAndItalicize.perform(); browserDriver.sendKeysToElement(BODY_XPATH, keys); }
From source file:com.liferay.faces.test.FACES1427PortletTest.java
License:Open Source License
@Test @RunAsClient/* w w w. j a va 2 s . c om*/ @InSequence(1300) public void steps89012() throws Exception { if (isThere(browser, errorMessageXpath) && errorMessage.isDisplayed()) { return; } logger.log(Level.INFO, "8: textarea1.getAttribute('value') = " + textarea1.getAttribute("value")); // click into textarea1 textarea1.click(); Thread.sleep(50); // move to the beginning of textarea1 textarea1.sendKeys(Keys.HOME); // firefox cursor is on the left after the last click, in chromium cursor is on // the right of the text ... grr Thread.sleep(50); // arrow over to the word 'initial' textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); textarea1.sendKeys(Keys.ARROW_RIGHT); Thread.sleep(50); // delete the word 'initial' textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); textarea1.sendKeys(Keys.DELETE); Thread.sleep(50); // type the word 'subsequent' textarea1.sendKeys("subsequent"); Thread.sleep(50); // select the word 'subsequent' ... easier said than done logger.log(Level.INFO, "8: textarea1.getAttribute('id') = '" + textarea1.getAttribute("id") + "'"); logger.log(Level.INFO, "8: before selecting ... selectText.getSelection(id) = " + selectText.getSelection(textarea1.getAttribute("id"))); Thread.sleep(500); logger.log(Level.INFO, "8: selectText.getSelection('id', 10, 20) ... "); selectText.setSelection(textarea1.getAttribute("id"), 10, 20); Thread.sleep(1000); logger.log(Level.INFO, "8: after selecting ... selectText.getSelection(id) = " + selectText.getSelection(textarea1.getAttribute("id"))); Thread.sleep(500); logger.log(Level.INFO, "8: isThere(browser, bold1Xpath) = " + isThere(browser, bold1Xpath)); logger.log(Level.INFO, "8: bold1.isDisplayed() = " + bold1.isDisplayed()); logger.log(Level.INFO, "8: bold1.getAttribute('src') = " + bold1.getAttribute("src")); logger.log(Level.INFO, "8: bold1.getLocation() = " + bold1.getLocation()); logger.log(Level.INFO, "8: clicking the bold1 button ..."); // click the bold1 button to make the word 'subsequent' bold try { bold1.click(); } catch (Exception e) { // apparently things are different in chromium logger.log(Level.INFO, "8: e.getMessage() = " + e.getMessage()); (new Actions(browser)).moveToElement(bold1, 3, 3).click(bold1).build().perform(); Thread.sleep(500); (new Actions(browser)).moveToElement(bold1, 3, 3).click().build().perform(); Thread.sleep(500); (new Actions(browser)).moveToElement(bold1).doubleClick().build().perform(); Thread.sleep(500); } Thread.sleep(50); // move into iframe1 logger.log(Level.INFO, "9: clicking into iframe1 ..."); iframe1.click(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.TAB).perform(); Thread.sleep(50); // arrow over to the word 'initial' (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform(); Thread.sleep(50); // delete the word 'initial' (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform(); Thread.sleep(50); // type the word 'subsequent' (new Actions(browser)).sendKeys("subsequent").perform(); Thread.sleep(50); // select the word 'subsequent' ... easier said than done (new Actions(browser)).keyDown(iframe1, Keys.SHIFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT) .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT) .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).keyUp(iframe1, Keys.SHIFT).build() .perform(); Thread.sleep(50); // click the bold2 button to make the word 'subsequent' bold logger.log(Level.INFO, "9: clicking on the bold button in the second editor ..."); bold2.click(); Thread.sleep(50); // Why do we need to click the iframe before clicking the submit button? Who knows? iframe1.click(); Thread.sleep(50); // submit the form logger.log(Level.INFO, "10: clicking the submit button ..."); submit.click(); Thread.sleep(50); // log some elements logger.log(Level.INFO, "11: comments1Output.getText() = " + comments1Output.getText()); logger.log(Level.INFO, "12: comments2Output.getText() = " + comments2Output.getText()); // assert to test assertTrue( "the submitted value for the FIRST editor should be 'comments1-[b]subsequent[/b]-value', but " + "it is '" + comments1Output.getText() + "'", comments1Output.getText().equals("comments1-[b]subsequent[/b]-value")); assertTrue( "the submitted value for the SECOND editor should be 'comments2-[b]subsequent[/b]-value', but " + "it is '" + comments2Output.getText() + "'", comments2Output.getText().equals("comments2-[b]subsequent[/b]-value")); }
From source file:com.opera.core.systems.DriverKeysTest.java
License:Apache License
@Test public void testLeftArrow() { new Actions(driver).sendKeys("ac" + Keys.LEFT + "b").build().perform(); assertEquals("abc", fieldOne.getAttribute("value")); }
From source file:com.opera.core.systems.DriverKeysTest.java
License:Apache License
@Test public void testCaseInsensitiveLeftArrow() { new Actions(driver).sendKeys("ac" + Keys.LEFT + "b").build().perform(); assertEquals("abc", fieldOne.getAttribute("value")); }