List of usage examples for org.openqa.selenium Keys CONTROL
Keys CONTROL
To view the source code for org.openqa.selenium Keys CONTROL.
Click Source Link
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
@Override public void pressKey(Key key) { switch (key) { case Shift:/* w ww . jav a 2s . co m*/ m_actionBuilder.keyDown(Keys.SHIFT); m_modifierPressed = true; break; case Control: m_actionBuilder.keyDown(Keys.CONTROL); // m_bot.controlKeyDown(); // m_bot.keyDownNative("17"); // m_keyList.add(Keys.CONTROL); m_modifierPressed = true; break; case Alt: m_actionBuilder.keyDown(Keys.ALT); m_modifierPressed = true; break; case Windows: m_actionBuilder.keyDown(Keys.META); m_modifierPressed = true; break; default: m_actionBuilder.sendKeys(toSeleniumKey(key).toString()); m_actionBuilder.perform(); // m_bot.keyDown(m_currentWidgetId, toSeleniumKey(key)); waitForIdle(); break; } }
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
@Override public void releaseKey(Key key) { switch (key) { case Shift://w w w. j ava2s .c o m m_actionBuilder.keyUp(Keys.SHIFT); m_modifierPressed = false; break; case Control: m_actionBuilder.keyUp(Keys.CONTROL); // m_bot.controlKeyUp(); // m_bot.keyUpNative("17"); // getCurrentElement().sendKeys(m_keyList.toArray(new CharSequence[m_keyList.size()])); // m_keyList.clear(); // getCurrentElement().sendKeys(Keys.CONTROL, "a"); m_modifierPressed = false; break; case Alt: m_actionBuilder.keyUp(Keys.ALT); m_modifierPressed = false; break; case Windows: m_actionBuilder.keyUp(Keys.META); m_modifierPressed = false; break; default: m_actionBuilder.keyUp(toSeleniumKey(key)); // m_bot.keyUp(m_currentWidgetId, toSeleniumKey(key)); break; } m_actionBuilder.perform(); waitForIdle(); }
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
protected Keys toSeleniumKey(Key key) { switch (key) { case Shift:/*from w ww . j av a2 s.c o m*/ return Keys.SHIFT; case Control: return Keys.CONTROL; case Alt: return Keys.ALT; case Delete: return Keys.DELETE; case Backspace: return Keys.BACK_SPACE; case Enter: return Keys.ENTER; case Esc: return Keys.ESCAPE; case Tab: return Keys.TAB; case ContextMenu: throw new IllegalArgumentException("Unknown keyboard key: " + key); case Up: return Keys.UP; case Down: return Keys.DOWN; case Left: return Keys.LEFT; case Right: return Keys.RIGHT; case Windows: return Keys.META; case F1: return Keys.F1; case F2: return Keys.F2; case F3: return Keys.F3; case F4: return Keys.F4; case F5: return Keys.F5; case F6: return Keys.F6; case F7: return Keys.F7; case F8: return Keys.F8; case F9: return Keys.F9; case F10: return Keys.F10; case F11: return Keys.F11; case F12: return Keys.F12; case Home: return Keys.HOME; case End: return Keys.END; case PageUp: return Keys.PAGE_UP; case PageDown: return Keys.PAGE_DOWN; case NumPad0: return Keys.NUMPAD0; case NumPad1: return Keys.NUMPAD1; case NumPad2: return Keys.NUMPAD2; case NumPad3: return Keys.NUMPAD3; case NumPad4: return Keys.NUMPAD4; case NumPad5: return Keys.NUMPAD5; case NumPad6: return Keys.NUMPAD6; case NumPad7: return Keys.NUMPAD7; case NumPad8: return Keys.NUMPAD8; case NumPadMultiply: return Keys.MULTIPLY; case NumPadDivide: return Keys.DIVIDE; case NumPadAdd: return Keys.ADD; case NumPadSubtract: return Keys.SUBTRACT; case NumPadDecimal: return Keys.DECIMAL; case NumPadSeparator: return Keys.SEPARATOR; default: throw new IllegalArgumentException("Unknown keyboard key: " + key); } }
From source file:org.glowroot.agent.webdriver.tests.Utils.java
License:Apache License
public static void clearInput(WebElement element) { // select text (control-a) then hit backspace key element.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE); }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
public void zoomIn(int times) { WebElement html = driver.findElement(By.tagName("html")); for (int i = 0; i < times; i++) { if (isMacOS()) { html.sendKeys(Keys.chord(Keys.COMMAND, Keys.ADD)); } else {//from w w w . j a va 2s . co m html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD)); } } }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
public void zoomOut(int times) { WebElement html = driver.findElement(By.tagName("html")); for (int i = 0; i < times; i++) { if (isMacOS()) { html.sendKeys(Keys.chord(Keys.COMMAND, Keys.SUBTRACT)); } else {//from w ww . java 2 s .c o m html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT)); } } }
From source file:org.julianharty.accessibility.automation.LayoutAndOrdering.java
License:Apache License
/** * A hack that applies a modifier key several times to a web browser. * //from w w w . j ava2 s . c o m * The aim is to increase or decrease the rendered font size and determine * how the reported location of a given web element varies. * * TODO(jharty): enable an ordered set of keys to be passed in by the * caller e.g. Keys.CONTROL, Keys.ADD * * TODO(jharty): find a way to compare the locations for a set of points. * This may become more generalised to allow a caller to pass in either a * generated set of points (e.g. a result of applying CTRL+ several times) * or a pre-determined set of points e.g. for known locations of a set of * elements on a web page. * * TODO(jharty): hmmm, needs refactoring anyway as the comparison of points * needs to reflect the direction of the change. Consider creating a * Direction enum with 2 values: INCREASE, DECREASE, which would obviate * the need to pass in a set of keystrokes and make the method tightly * focused. * * @param currentElement the element that currently has focus. * @param maxChanges the number of times the keystroke will be applied. * @param modifierKey the key to apply, currently expected to be Keys.ADD * or Keys.SUBTRACT */ private void applyModifierKeyTo(WebElement currentElement, int maxChanges, Keys modifierKey) { Point currentElementLocation = currentElement.getLocation(); for (int i = 0; i < maxChanges; i++) { currentElement.sendKeys(Keys.CONTROL, modifierKey); Point newLocation = currentElement.getLocation(); System.out.println(GeneralHelpers.printElementLocations(i, currentElementLocation, newLocation)); if (GeneralHelpers.compareElementLocationsForSaneTabOrder(currentElementLocation, newLocation, tolerance)) { fail(GeneralHelpers.printElementLocations(i, currentElementLocation, newLocation)); } currentElementLocation = newLocation; } }
From source file:org.musetest.selenium.values.KeystrokesStringSourceTests.java
License:Open Source License
@Test void testControlChar() throws MuseInstantiationException, ValueSourceResolutionError { ValueSourceConfiguration source = ValueSourceConfiguration.forTypeWithSource(KeystrokesStringSource.TYPE_ID, ValueSourceConfiguration.forValue("{CONTROL-A}")); Object result = source.createSource(new SimpleProject()).resolveValue(new MockStepExecutionContext()); Assertions.assertEquals(Keys.chord(Keys.CONTROL, "A"), result.toString()); }
From source file:org.natica.expense.ExpenseImport.java
public void importExpenes(List<Expense> expenses, String username, String password) { setUpDriverConfig(ExpenseConstants.WAITSECONDS); openBrowser();//from www . j a va2 s.c o m login(username, password); goToExpensePage(); for (Expense e : expenses) { WebElement calendarButton = driver.findElement(By.xpath(ExpenseConstants.CALENDARPOPUPXPATH)); calendarButton.click(); String activeMonthYear = driver.findElement(By.xpath(ExpenseConstants.CALENDARACTIVEMONTHXPATH)) .getText(); DateFormat format = new SimpleDateFormat("MMMM yyyy"); Date activeDate = null; try { activeDate = format.parse(activeMonthYear); } catch (ParseException ex) { Logger.getLogger(ExpenseImport.class.getName()).log(Level.SEVERE, null, ex); } Calendar activeDateCal = Calendar.getInstance(); activeDateCal.setTime(activeDate); Calendar expenseEntryDateCal = Calendar.getInstance(); expenseEntryDateCal.setTime(e.getExpenseEntryDate()); goToExpenseMonth(activeDateCal, expenseEntryDateCal); WebElement expenseDay = findDay(expenseEntryDateCal.get(Calendar.DAY_OF_MONTH), expenseEntryDateCal.getActualMaximum(Calendar.DATE)); expenseDay.click(); WebElement showButton = driver.findElement(By.xpath(ExpenseConstants.SHOWBUTTONXPATH)); showButton.click(); WebElement projectName = driver.findElement(By.xpath(ExpenseConstants.PROJECTNAMEXPATH)); Select projectNameSelect = new Select(projectName); projectNameSelect.selectByVisibleText(e.getProjectName()); WebElement expenseName = driver.findElement(By.xpath(ExpenseConstants.EXPENSENAMEXPATH)); Select expenseNameSelect = new Select(expenseName); expenseNameSelect.selectByVisibleText(e.getExpenseName()); expenseName.sendKeys(Keys.TAB); waitSeconds(3); WebElement description = driver.findElement(By.xpath(ExpenseConstants.EXPENSEDESCRIPTIONXPATH)); description.sendKeys(Keys.chord(Keys.CONTROL, "a"), e.getDescription()); description.sendKeys(Keys.TAB); WebElement paymentMethod = driver.findElement(By.xpath(ExpenseConstants.PAYMENTMETHODXPATH)); Select paymentMethodSelect = new Select(paymentMethod); paymentMethodSelect.selectByVisibleText(e.getPaymentMethod()); WebElement netAmount = driver.findElement(By.xpath(ExpenseConstants.NETAMOUNTXPATH)); netAmount.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END), e.getNetAmount().toString().replace(".", ",")); netAmount.sendKeys(Keys.TAB); waitSeconds(3); WebElement addButton = driver.findElement(By.xpath(ExpenseConstants.ADDBUTTONXPATH)); addButton.click(); acceptNextAlert = true; closeAlertAndGetItsText(); WebElement submitButton = driver.findElement(By.xpath(ExpenseConstants.SUBMITBUTTONXPATH)); submitButton.click(); } }
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 2s. 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(); }