/** * Returns sequence of backspaces and deletes that will clear element. * clear() can't be used because generates separate onchange event * See https://github.com/yandex-qatools/htmlelements/issues/65 */ public String getClearCharSequence() { return StringUtils.repeat(Keys.DELETE.toString() + Keys.BACK_SPACE, getText().length()); } }
/** * Returns sequence of backspaces and deletes that will clear element. * clear() can't be used because generates separate onchange event * See https://github.com/yandex-qatools/htmlelements/issues/65 */ public String getClearCharSequence() { return StringUtils.repeat(Keys.DELETE.toString() + Keys.BACK_SPACE, getText().length()); } }
/** * Returns sequence of backspaces and deletes that will clear element. * clear() can't be used because generates separate onchange event * See https://github.com/yandex-qatools/htmlelements/issues/65 */ public String getClearCharSequence() { return StringUtils.repeat(Keys.DELETE.toString() + Keys.BACK_SPACE, getText().length()); } }
@Override protected CharSequence[] modifyCharSequence(CharSequence... keysToSend) { final List<CharSequence> modKeysToSend = newArrayList(); for (CharSequence charSequence : keysToSend) { final String key = charSequence.toString(); if (Keys.END.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.RIGHT)); } else if (Keys.HOME.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.LEFT)); } else if (Keys.PAGE_UP.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.UP)); } else if (Keys.PAGE_DOWN.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.DOWN)); } else { modKeysToSend.add(charSequence); } } return modKeysToSend.toArray(new CharSequence[modKeysToSend.size()]); } }
/** * Compared to using clear() + sendKeys(), this method ensures that an "input" event is triggered on the JavaScript * side for an empty ("") value. Without this, the clear() method triggers just a "change" event. * * @param textInputElement an element accepting text input * @param newTextValue the new text value to set * @see <a href="https://code.google.com/p/selenium/issues/detail?id=214">Issue 214</a> * @since 7.2M3 */ public void setTextInputValue(WebElement textInputElement, String newTextValue) { if (StringUtils.isEmpty(newTextValue)) { // Workaround for the fact that clear() fires the "change" event but not the "input" event and javascript // listening to the "input" event will not be executed otherwise. // Note 1: We're not using CTRL+A and the Delete because the key combination to select the full input // depends on the OS (on Mac it's META+A for example). // Note 2: Sending the END key didn't always work when I tested it on Mac (for some unknown reason) textInputElement.click(); textInputElement.sendKeys( StringUtils.repeat(Keys.ARROW_RIGHT.toString(), textInputElement.getAttribute("value").length())); textInputElement.sendKeys( StringUtils.repeat(Keys.BACK_SPACE.toString(), textInputElement.getAttribute("value").length())); } else { textInputElement.clear(); textInputElement.sendKeys(newTextValue); } }
private String mapAsciiKeyCodeToKey (int keyCode) { Map<Integer, Keys> keysMap = new HashMap<Integer, Keys>(); keysMap.put(0,Keys.NULL); 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(); }
/** * Send key to element and add corresponding parameter to allure report * * @param webElement WebElement to send keys in * @param keyName name of the key. See available key names in {@link Keys} */ public void pressKey(WebElement webElement, Keys keyName) { webElement.sendKeys(keyName); ParamsHelper.addParam("\"%s\" is pressed by key \"%s\"", new String[]{getElementTitle(webElement), keyName.toString()}); }
void keysType(final CharSequence... charsList) { for (CharSequence chars : charsList) { if (Util.KEYBOARD_DELETE.equals(chars.toString())) { keysTypeHelper(Keys.chord(Keys.CONTROL, "a")); keysTypeHelper(Keys.BACK_SPACE.toString()); } else { keysTypeHelper(chars); } } }
public void press(Keys key) { editArea.sendKeys(key); Log.log("press", "key " + key.toString() + "pressed", true); }
public void pressEnter() { getAction().sendKeys(ENTER.toString()).perform(); }
public void pressArrowDown() { getAction().sendKeys(ARROW_DOWN.toString()).perform(); }
public void pressArrowUp() { getAction().sendKeys(ARROW_UP.toString()).perform(); }
public void pressArrowLeft() { getAction().sendKeys(ARROW_LEFT.toString()).perform(); }
public void pressDelete() { getAction().sendKeys(DELETE.toString()).perform(); }
public void pressArrowRight() { getAction().sendKeys(ARROW_RIGHT.toString()).perform(); }
public void pressBackspace() { getAction().sendKeys(BACK_SPACE.toString()).perform(); }