List of usage examples for org.openqa.selenium Keys DELETE
Keys DELETE
To view the source code for org.openqa.selenium Keys DELETE.
Click Source Link
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
private String mapAsciiKeyCodeToKey(int keyCode) { Map<Integer, Keys> keysMap = new HashMap<Integer, Keys>(); keysMap.put(0, Keys.NULL);/*from ww w. j av a2 s . c o m*/ keysMap.put(8, Keys.BACK_SPACE); keysMap.put(9, Keys.TAB); keysMap.put(10, Keys.RETURN); keysMap.put(13, Keys.ENTER); keysMap.put(24, Keys.CANCEL); keysMap.put(27, Keys.ESCAPE); keysMap.put(32, Keys.SPACE); keysMap.put(42, Keys.MULTIPLY); keysMap.put(43, Keys.ADD); keysMap.put(44, Keys.SUBTRACT); keysMap.put(56, Keys.DECIMAL); keysMap.put(57, Keys.DIVIDE); keysMap.put(59, Keys.SEMICOLON); keysMap.put(61, Keys.EQUALS); keysMap.put(127, Keys.DELETE); Keys key = keysMap.get(keyCode); if (key == null) { Character c = (char) keyCode; return c.toString(); } return key.toString(); }
From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java
License:Apache License
/** * This methods checks that once a simple html input is changed within a page, the new value is stored in the * browser local storage in case of accidental loose (crash, freeze, network failure). The value can then be * restored from the local storage when re-editing the page afterwards. * * @since 5.7.1// w w w . j a v a 2 s .c o m */ @Test public void testAutoSaveOnChangeAndRestore() throws Exception { if (!runTestForBrowser()) { log.warn("Browser not supported. Nothing to run."); return; } WebElement descriptionElt, titleElt; login(TEST_USERNAME, TEST_PASSWORD); open(String.format(NXDOC_URL_FORMAT, wsId)); DocumentBasePage documentBasePage = asPage(DocumentBasePage.class); documentBasePage.getEditTab(); LocalStorage localStorage = new LocalStorage(driver); localStorage.clearLocalStorage(); String currentDocumentId = getCurrentDocumentId(); descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID)); titleElt = driver.findElement(By.name(TITLE_ELT_ID)); log.debug("1 - " + localStorage.getLocalStorageLength()); // We change the value of the title Keys ctrlKey = Keys.CONTROL; if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) { ctrlKey = Keys.COMMAND; } titleElt.click(); titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE); // weird thing in webdriver: we need to call clear on an input of the // form to fire an onchange event Locator.scrollToElement(descriptionElt); descriptionElt.click(); descriptionElt.clear(); log.debug("2 - " + localStorage.getLocalStorageLength()); // avoid randoms: wait for the local storage to actually hold the saved values after 10s Locator.waitUntilGivenFunction(input -> { LocalStorage ls = new LocalStorage(driver); String content = ls.getItemFromLocalStorage(wsId); log.debug(content); return content != null && content.contains(NEW_WORKSPACE_TITLE); }); // Now must have something saved in the localstorage String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\""; assertTrue(lsItem != null && lsItem.length() > 0); assertTrue(lsItem.contains(lookupString)); // Let's leave the edit tab of the workspace with unsaved changes. A // popup should also prevent us from doing that, let's bypass it for tests log.debug("3 - " + localStorage.getLocalStorageLength()); bypassPopup(); driver.findElement(By.linkText("Sections")).click(); log.debug("4 - " + localStorage.getLocalStorageLength()); // Get back to edit tab. Since we didn't save, the title must be the initial one. open(String.format(NXDOC_URL_FORMAT, wsId)); documentBasePage = asPage(DocumentBasePage.class); documentBasePage.getEditTab(); localStorage = new LocalStorage(driver); titleElt = Locator.findElementWithTimeout(By.name(TITLE_ELT_ID)); String titleEltValue = titleElt.getAttribute("value"); assertEquals(WORKSPACE_TITLE, titleEltValue); log.debug("5 - " + localStorage.getLocalStorageLength()); // We must find in the localstorage an entry matching the previous // document which contains the title we edited lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); assertNotNull(lsItem); assertTrue(lsItem.contains(lookupString)); log.debug("6 - " + localStorage.getLocalStorageLength()); checkSafeEditRestoreProvided(); triggerSafeEditRestore(); // We check that the title value has actually been restored titleElt = driver.findElement(By.name(TITLE_ELT_ID)); titleEltValue = titleElt.getAttribute("value"); assertEquals(NEW_WORKSPACE_TITLE, titleEltValue); // try to leave again if (documentBasePage.useAjaxTabs()) { AjaxRequestManager arm = new AjaxRequestManager(driver); arm.begin(); documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false); leaveTabPopup(false); arm.end(); } else { documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false); leavePagePopup(false); } driver.findElement(By.linkText("Sections")).click(); leavePagePopup(true); logout(); }
From source file:org.nuxeo.functionaltests.ITSafeEditTest.java
License:Open Source License
/** * This methods checks that once a simple html input is changed within a * page, the new value is stored in the browser local storage in case of * accidental loose (crash, freeze, network failure). The value can then be * restored from the local storage when re-editing the page afterwards. * * @since 5.7.1/*from w w w .j ava2 s . co m*/ */ @Test public void testAutoSaveOnChangeAndRestore() throws Exception { if (!runTestForBrowser()) { log.warn("Browser not supported. Nothing to run."); return; } prepare(); DocumentBasePage documentBasePage; WebElement descriptionElt, titleElt; // Log as test user and edit the created workdspace documentBasePage = login(USERNAME, PASSWORD).getContentTab().goToDocument("Workspaces").getContentTab() .goToDocument(WORKSPACE_TITLE); documentBasePage.getEditTab(); LocalStorage localStorage = new LocalStorage(driver); localStorage.clearLocalStorage(); String currentDocumentId = getCurrentDocumentId(); descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID)); titleElt = driver.findElement(By.name(TITLE_ELT_ID)); log.debug("1 - " + localStorage.getLocalStorageLength()); // We change the value of the title Keys ctrlKey = Keys.CONTROL; if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) { ctrlKey = Keys.COMMAND; } titleElt.click(); titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE); // weird thing in webdriver: we need to call clear on an input of the // form to fire an onchange event descriptionElt.click(); descriptionElt.clear(); log.debug("2 - " + localStorage.getLocalStorageLength()); // Now must have something saved in the localstorage String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\""; assertTrue(lsItem != null && lsItem.length() > 0); assertTrue(lsItem.contains(lookupString)); // Let's leave the edit tab of the workspace with unsaved changes. A // popup should prevent us from doing that try { documentBasePage.getContentTab(); // Should never occur fail("There are unsaved modifications pending and the page can only be left after clicking \"Leave this page\""); } catch (UnhandledAlertException e) { // Expected behavior // The following is a workaround to by pass the popup windows which // is supposed to prevent the user from leaving the page with // unsaved modifications log.debug("3 - " + localStorage.getLocalStorageLength()); byPassLeavePagePopup(); log.debug("4 - " + localStorage.getLocalStorageLength()); } // We leave the page and get back to it. Since we didn't save, the // title must be the initial one. documentBasePage.getContentTab(); documentBasePage.getEditTab(); localStorage = new LocalStorage(driver); titleElt = findElementWithTimeout(By.name(TITLE_ELT_ID)); String titleEltValue = titleElt.getAttribute("value"); assertTrue(titleEltValue.equals(WORKSPACE_TITLE)); log.debug("5 - " + localStorage.getLocalStorageLength()); // We must find in the localstorage an entry matching the previous // document which contains the title we edited lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); assertTrue(lsItem.contains(lookupString)); log.debug("6 - " + localStorage.getLocalStorageLength()); checkSafeEditRestoreProvided(); triggerSafeEditResotre(); // We check that the title value has actually been restored titleElt = driver.findElement(By.name(TITLE_ELT_ID)); titleEltValue = titleElt.getAttribute("value"); assertTrue(titleEltValue.equals(NEW_WORKSPACE_TITLE)); byPassLeavePagePopup(); documentBasePage.getContentTab(); logout(); restoreSate(); }
From source file:org.nvonop.selenium.framework.controls.TextBox.java
License:Open Source License
@Override public void write(String value) { getUnderlyingWebElement().sendKeys(Keys.HOME); getUnderlyingWebElement().sendKeys(Keys.SHIFT, Keys.END, Keys.DELETE); getUnderlyingWebElement().sendKeys(value); }
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); }//from ww w. j a v a2s. 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.richfaces.tests.showcase.notify.page.NotifyAttributesPage.java
License:Open Source License
public void setStayTime(long time) { inputForStayTime.click();/*from ww w.jav a2 s . co m*/ inputForStayTime.clear(); inputForStayTime.click(); actions.sendKeys(inputForStayTime, Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.DELETE, Keys.DELETE, Keys.DELETE, Long.toString(time)).build().perform(); }
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 ww w.j ava 2 s.com*/ * @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.WDLibrary.java
License:Open Source License
/** * Convert a Java KEYCODE to a Selenium WebDriver Keys Enum * @param keycode int, a java keycode/* www . ja v a 2s . c o m*/ * @return Keys enum for (primarily) non-printable (control) characters, or null. */ public static Keys convertToKeys(int keycode) { Keys key = null; switch (keycode) { case java.awt.event.KeyEvent.VK_ADD: key = Keys.ADD; break; case java.awt.event.KeyEvent.VK_ALT: key = Keys.ALT; break; case java.awt.event.KeyEvent.VK_KP_DOWN: key = Keys.ARROW_DOWN; break; case java.awt.event.KeyEvent.VK_KP_LEFT: key = Keys.ARROW_LEFT; break; case java.awt.event.KeyEvent.VK_KP_RIGHT: key = Keys.ARROW_RIGHT; break; case java.awt.event.KeyEvent.VK_KP_UP: key = Keys.ARROW_UP; break; case java.awt.event.KeyEvent.VK_BACK_SPACE: key = Keys.BACK_SPACE; break; case java.awt.event.KeyEvent.VK_CANCEL: key = Keys.CANCEL; break; case java.awt.event.KeyEvent.VK_CLEAR: key = Keys.CLEAR; break; case java.awt.event.KeyEvent.VK_WINDOWS: key = Keys.COMMAND; break; case java.awt.event.KeyEvent.VK_CONTROL: key = Keys.CONTROL; break; case java.awt.event.KeyEvent.VK_DECIMAL: key = Keys.DECIMAL; break; case java.awt.event.KeyEvent.VK_DELETE: key = Keys.DELETE; break; case java.awt.event.KeyEvent.VK_DIVIDE: key = Keys.DIVIDE; break; case java.awt.event.KeyEvent.VK_DOWN: key = Keys.DOWN; break; case java.awt.event.KeyEvent.VK_END: key = Keys.END; break; case java.awt.event.KeyEvent.VK_ENTER: key = Keys.ENTER; break; case java.awt.event.KeyEvent.VK_EQUALS: key = Keys.EQUALS; break; case java.awt.event.KeyEvent.VK_ESCAPE: key = Keys.ESCAPE; break; case java.awt.event.KeyEvent.VK_F1: key = Keys.F1; break; case java.awt.event.KeyEvent.VK_F2: key = Keys.F2; break; case java.awt.event.KeyEvent.VK_F3: key = Keys.F3; break; case java.awt.event.KeyEvent.VK_F4: key = Keys.F4; break; case java.awt.event.KeyEvent.VK_F5: key = Keys.F5; break; case java.awt.event.KeyEvent.VK_F6: key = Keys.F6; break; case java.awt.event.KeyEvent.VK_F7: key = Keys.F7; break; case java.awt.event.KeyEvent.VK_F8: key = Keys.F8; break; case java.awt.event.KeyEvent.VK_F9: key = Keys.F9; break; case java.awt.event.KeyEvent.VK_F10: key = Keys.F10; break; case java.awt.event.KeyEvent.VK_F11: key = Keys.F11; break; case java.awt.event.KeyEvent.VK_F12: key = Keys.F12; break; case java.awt.event.KeyEvent.VK_HELP: key = Keys.HELP; break; case java.awt.event.KeyEvent.VK_HOME: key = Keys.HOME; break; case java.awt.event.KeyEvent.VK_INSERT: key = Keys.INSERT; break; case java.awt.event.KeyEvent.VK_LEFT: key = Keys.LEFT; break; case java.awt.event.KeyEvent.VK_META: key = Keys.META; break; case java.awt.event.KeyEvent.VK_MULTIPLY: key = Keys.MULTIPLY; break; case java.awt.event.KeyEvent.VK_NUMPAD0: key = Keys.NUMPAD0; break; case java.awt.event.KeyEvent.VK_NUMPAD1: key = Keys.NUMPAD1; break; case java.awt.event.KeyEvent.VK_NUMPAD2: key = Keys.NUMPAD2; break; case java.awt.event.KeyEvent.VK_NUMPAD3: key = Keys.NUMPAD3; break; case java.awt.event.KeyEvent.VK_NUMPAD4: key = Keys.NUMPAD4; break; case java.awt.event.KeyEvent.VK_NUMPAD5: key = Keys.NUMPAD5; break; case java.awt.event.KeyEvent.VK_NUMPAD6: key = Keys.NUMPAD6; break; case java.awt.event.KeyEvent.VK_NUMPAD7: key = Keys.NUMPAD7; break; case java.awt.event.KeyEvent.VK_NUMPAD8: key = Keys.NUMPAD8; break; case java.awt.event.KeyEvent.VK_NUMPAD9: key = Keys.NUMPAD9; break; case java.awt.event.KeyEvent.VK_PAGE_DOWN: key = Keys.PAGE_DOWN; break; case java.awt.event.KeyEvent.VK_PAGE_UP: key = Keys.PAGE_UP; break; case java.awt.event.KeyEvent.VK_PAUSE: key = Keys.PAUSE; break; case java.awt.event.KeyEvent.VK_RIGHT: key = Keys.RIGHT; break; case java.awt.event.KeyEvent.VK_SEMICOLON: key = Keys.SEMICOLON; break; case java.awt.event.KeyEvent.VK_SEPARATOR: key = Keys.SEPARATOR; break; case java.awt.event.KeyEvent.VK_SHIFT: key = Keys.SHIFT; break; case java.awt.event.KeyEvent.VK_SPACE: key = Keys.SPACE; break; case java.awt.event.KeyEvent.VK_SUBTRACT: key = Keys.SUBTRACT; break; case java.awt.event.KeyEvent.VK_TAB: key = Keys.TAB; break; case java.awt.event.KeyEvent.VK_UP: key = Keys.UP; break; } return key; }
From source file:org.tomitribe.tribestream.registryng.functionaltests.pages.SearchPage.java
License:Apache License
public void refresh() throws InterruptedException { searchField.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.DELETE, Keys.RETURN); Thread.sleep(5000);/*from ww w.j a v a2s . c om*/ }
From source file:org.wso2.ds.ui.integration.test.dashboard.BannerTest.java
License:Open Source License
/** * Clicks the banner edit button. This pops up the file browser and upload the image for cropping. * * @throws MalformedURLException/*from w w w . j a v a2 s . c om*/ * @throws XPathExpressionException */ private void clickEditBannerButton(int imageIndex) throws MalformedURLException, XPathExpressionException { // Temporary display the HTML form which is used to upload the image getDriver().executeScript("document.getElementById('ues-dashboard-upload-banner-form').className='';"); // Get the sample_images directory ClassLoader classLoader = BannerTest.class.getClassLoader(); File classPathRoot = new File(classLoader.getResource("").getPath()); String filePath = Paths.get(classPathRoot.getAbsolutePath(), "sample_images", IMAGES[imageIndex]) .toString(); if (LOG.isDebugEnabled()) { File file = new File(filePath); if (!file.exists()) { LOG.debug("Unable to find the sample image file at " + filePath); } } getDriver().findElement(By.id("file-banner")).sendKeys(Keys.DELETE); getDriver().findElement(By.id("file-banner")).sendKeys(filePath); }