List of usage examples for org.openqa.selenium Keys BACK_SPACE
Keys BACK_SPACE
To view the source code for org.openqa.selenium Keys BACK_SPACE.
Click Source Link
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.AemRichText.java
License:Apache License
/** * Clears the content of richtext's text area. * * @return This instance./*from w w w .j av a2 s .co m*/ */ public AemRichText clear() { switchToTextArea(); try { bobcatWait.withTimeout(Timeouts.BIG).until(driver -> { actions.sendKeys(Keys.chord(Keys.CONTROL, "a")).sendKeys(Keys.BACK_SPACE).sendKeys(Keys.BACK_SPACE) .perform(); WebElement activeElement = webDriver.switchTo().activeElement(); String text = activeElement.getText(); return text.isEmpty(); }, 2); return this; } finally { frameSwitcher.switchBack(); } }
From source file:com.cognifide.qa.bb.test.actions.BobcatActionsTest.java
License:Apache License
@Test public void shouldBeBlankAfterClear() { //given//w w w.ja v a 2 s . com shouldContainTextAfterTextSendKeys(); //when actions.sendKeys(inputElement, Keys.chord(Keys.CONTROL, "a")).sendKeys(Keys.BACK_SPACE).perform(); //then assertThat(getTextFromInputElement()).isEmpty(); }
From source file:com.cognifide.qa.bb.test.actions.BobcatActionsTest.java
License:Apache License
@Test public void whenIPressBackSpaceLastLetterIsRemoved() { //when//from ww w .j av a 2 s . c o m actions.sendKeys(inputElement, TEXT_TO_SEND, StringUtils.SPACE, TEXT_TO_SEND, Keys.BACK_SPACE).perform(); //then assertThat(getTextFromInputElement()).endsWith(StringUtils.chop(TEXT_TO_SEND)); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./*from w w w . j a v a 2 s. c om*/ */ @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./*from w w w. j a v a 2 s .com*/ */ @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.hotwire.selenium.mobile.search.HotelSearchFragment.java
License:Open Source License
private void typeLocationAndClickOnMatch(String destinationLocation, int subStringLength) { // Split up string to grab the first 3 characters as this is the first trigger to the // autocomplete menu showing up. Guard against IndexOutOfBoundsException. int substringLength = subStringLength; String startString = (destinationLocation.length() > substringLength) ? destinationLocation.substring(0, substringLength) : destinationLocation;//from ww w.j a v a 2s. c om // Get the start autocomplete list. This list is always visible. It initially contains "Current Location" item. List<WebElement> acList = getWebDriver().findElements(By.cssSelector(DESTINATION_LAYER_LOCATIONS_LIST)); hotelLocation.click(); hotelLocation.clear(); hotelLocation.sendKeys(startString); try { waitForAutoCompleteListToChange(getWebDriver(), acList); } catch (TimeoutException e) { /* Do nothing. The user might type something that has no matches. */ } acList = getWebDriver().findElements(By.cssSelector(DESTINATION_LAYER_LOCATIONS_LIST)); boolean matchFound = false; for (WebElement item : acList) { if (item.getText().trim().toLowerCase().equals(destinationLocation.trim().toLowerCase())) { logger.info("Exact location match for " + destinationLocation + " found in location autocomplete. Clicking menu item."); matchFound = true; item.click(); break; } } if (!matchFound) { for (WebElement item : acList) { if (item.getText().trim().toLowerCase().contains(destinationLocation.trim().toLowerCase())) { logger.info("Autocomplete menu item found that contains " + destinationLocation + " as substring. Clicking menu item."); matchFound = true; item.click(); break; } } if (!matchFound) { logger.info("NO exact or substring location match for " + destinationLocation + ". Typing location manually."); for (int i = 0; i < substringLength; i++) { hotelLocation.sendKeys(Keys.BACK_SPACE); } hotelLocation.sendKeys(destinationLocation + Keys.ESCAPE); hotelLocation.submit(); } } }
From source file:com.liferay.faces.bridge.test.integration.demo.applicant.JSF_JSPApplicantPortletTester.java
License:Open Source License
@Override protected void clearAllFields(BrowserDriver browserDriver) { browserDriver.clearElement(getFirstNameFieldXpath()); browserDriver.clearElement(getLastNameFieldXpath()); browserDriver.clearElement(getEmailAddressFieldXpath()); browserDriver.clearElement(getPhoneNumberFieldXpath()); browserDriver.clearElement(getDateOfBirthFieldXpath()); browserDriver.clearElement(getCityFieldXpath()); clearProvince(browserDriver);//from w w w.ja va 2 s . c om Keys[] clearPostalCodeKeys = { Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE }; submitPostalCodeAndWaitForPostback(browserDriver, clearPostalCodeKeys); }
From source file:com.liferay.faces.bridge.test.integration.demo.JSF_IPCPortletsTesterBase.java
License:Open Source License
private void testEditName(BrowserDriver browserDriver, WaitingAsserter waitingAsserter, String customerId, boolean editFirstName) { // Test that the first and last names are the same in both portlets. String customerIdXpath = "//td[text()='" + customerId + "']"; String customerEditButtonXpath = customerIdXpath + "/..//input"; browserDriver.waitForElementEnabled(customerEditButtonXpath); browserDriver.clickElement(customerEditButtonXpath); browserDriver.waitForElementEnabled(firstNameInputXpath); String customerFirstNameXpath = customerIdXpath + "/following-sibling::td[1]"; WebElement firstNameElement = browserDriver.findElementByXpath(customerFirstNameXpath); String customerLastNameXpath = customerIdXpath + "/following-sibling::td[2]"; WebElement lastNameElement = browserDriver.findElementByXpath(customerLastNameXpath); String firstName = firstNameElement.getText(); waitingAsserter.assertTextPresentInElementValue(firstName, firstNameInputXpath); String lastName = lastNameElement.getText(); waitingAsserter.assertTextPresentInElementValue(lastName, lastNameInputXpath); // Test that editing the name changes it in the customers portlet. String inputXpath = firstNameInputXpath; String name = firstName;// ww w .j av a2 s . co m String customerNameXpath = customerFirstNameXpath; if (!editFirstName) { inputXpath = lastNameInputXpath; name = lastName; customerNameXpath = customerLastNameXpath; } browserDriver.clearElement(inputXpath); String editedName = name + "y"; browserDriver.sendKeysToElement(inputXpath, editedName); browserDriver.clickElement(submitButtonXpath); waitingAsserter.assertTextPresentInElement(editedName, customerNameXpath); // Reset the name. browserDriver.sendKeysToElement(inputXpath, Keys.BACK_SPACE); browserDriver.clickElement(submitButtonXpath); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient//from w w w . ja v a 2 s.c o m @InSequence(1500) public void dataEntry() throws Exception { String foo = ""; logger.log(Level.INFO, "clicking into the firstNameField ..."); firstNameField.click(); logger.log(Level.INFO, "tabbing into the next field ..."); firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); if (isThere(browser, firstNameFieldErrorXpath)) { // houston we have a problem logger.log(Level.INFO, "firstNameFieldError.isDisplayed() = " + firstNameFieldError.isDisplayed()); assertFalse( "firstNameFieldError should not be displayed after simply tabbing out of the empty field, having never entered any data. " + "But we see '" + firstNameFieldError.getText() + "'", firstNameFieldError.isDisplayed()); } logger.log(Level.INFO, "Shift tabbing back into the firstNameField ..."); (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyDown(Keys.SHIFT).perform(); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); logger.log(Level.INFO, "entering 'asdf' into the firstNameField and then tabbing out of it..."); firstNameField.sendKeys("asdf"); firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); assertTrue("The data 'asdf' should be in the firstNameField after tabbing out of it", "asdf".equals(firstNameField.getAttribute("value"))); logger.log(Level.INFO, "Shift tabbing back into the firstNameField ..."); (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform(); firstNameField.click(); logger.log(Level.INFO, "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ..."); firstNameField.sendKeys(Keys.ARROW_RIGHT, Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'asd' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "asd")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } logger.log(Level.INFO, "firstNameField.getText() = " + firstNameField.getText()); assertTrue( "firstNameField should contain 'asd', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'as' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "as")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue( "firstNameField should contain 'as', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain 'a' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "a")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue("firstNameField should contain 'a', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.BACK_SPACE); logger.log(Level.INFO, "Waiting for the firstNameField to contain '' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, firstNameFieldXpath)) { foo = firstNameField.getText(); } assertTrue("firstNameField should contain '', but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } firstNameField.sendKeys(Keys.TAB); logger.log(Level.INFO, "Waiting for the firstNameFieldError to contain 'Value is required' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(firstNameFieldErrorXpath), "Value is required")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("firstNameFieldError should be visible after tabbing out with no value," + " but " + firstNameFieldErrorXpath + " is not visible.", false); } logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value")); assertTrue( "The data 'asdf' should no longer be in the firstNameField after clearing it out with BACK_SPACE and then tabbing out. " + "But we see '" + firstNameField.getAttribute("value") + "'", "".equals(firstNameField.getAttribute("value"))); logger.log(Level.INFO, "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath)); assertTrue( "The firstNameFieldError should at least be in the DOM somewhere by this point, but it is not there", isThere(browser, firstNameFieldErrorXpath)); logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText()); assertTrue("The firstNameFieldError should say 'Value is required'", firstNameFieldError.getText().contains("Value is required")); }
From source file:com.liferay.faces.test.FACES1427PortletTest.java
License:Open Source License
@Test @RunAsClient/*from w w w . ja va 2 s . c o m*/ @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")); }