public void sendKeys(CharSequence... keysToSend) { verifyCanInteractWithElement(); // Handle special input types String typeAttribute = getAttribute("type").toLowerCase(); if (getTagName().equals("INPUT") && specialInputs.contains(typeAttribute)) { if (typeAttribute.equals("file")) { File localFile = fileDetector.getLocalFile(keysToSend); if (localFile != null) { debugger.setFormElementValue(objectId, localFile.getAbsolutePath()); } } else { debugger.setFormElementValue(objectId, Joiner.on("").join(keysToSend)); } return; } parent.getScopeServices().captureOperaIdle(); switchFocusToThisIfNeeded(); parent.getKeyboard().sendKeys(keysToSend); try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // return control to user } }
/** * @param parent driver that this element belongs to * @param objectId the EcmaScript object ID of this element */ public OperaWebElement(OperaDriver parent, int objectId) { this.parent = parent; this.objectId = objectId; parent.objectIds.add(objectId); debugger = parent.getScriptDebugger(); execService = parent.getExecService(); runtimeId = debugger.getRuntimeId(); }
/** * @param parent driver that this element belongs to * @param objectId the EcmaScript object ID of this element */ public OperaWebElement(OperaDriver parent, int objectId) { this.parent = parent; this.objectId = objectId; parent.objectIds.add(objectId); debugger = parent.getScriptDebugger(); execService = parent.getExecService(); runtimeId = debugger.getRuntimeId(); setId(String.valueOf(hashCode())); setFileDetector(parent.getFileDetector()); }
/** * Click the element at the given X,Y offset from the top left. * * @param x the distance from the left border of the element to click * @param y the distance from the top border of the element to click */ public void click(int x, int y) { parent.getScopeServices().captureOperaIdle(); parent.actionHandler.click(this, x, y); try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // This might be expected logger.fine("Response not received, returning control to user"); } }
public void submit() { parent.getScopeServices().captureOperaIdle(); evaluateMethod("return " + OperaAtom.SUBMIT + "(locator)"); try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // This might be expected logger.fine("Response not received, returning control to user"); } }
private List<WebElement> findMultipleElements(String using, String type) { Integer id = debugger.executeScriptOnObject(using, objectId); if (id == null) { throw new NoSuchElementException("Cannot find element(s) with " + type); } return parent.processElements(id); }
protected WebElement findElement(final String by, final String using) { final OperaWebElement el = this; return parent.implicitlyWaitFor( new Callable<WebElement>() { public WebElement call() { return parent.findElement(by, using, el); } }); }
// TODO(andreastt): OPDRV-199 public void click() { assertElementNotStale(); assertElementDisplayed(); parent.getScopeServices().captureOperaIdle(); if (getTagName().equals("OPTION")) { callMethod("return " + OperaAtom.CLICK + "(locator)"); } else { parent.getMouse().click(getCoordinates()); } try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // This might be expected logger.fine("Response not received, returning control to user"); } }
public void click() { assertElementDisplayed("Cannot click an element that is not displayed"); parent.getScopeServices().captureOperaIdle(); if (getTagName().equals("OPTION")) { assertElementEnabled("Cannot select disabled element"); callMethod("return " + OperaAtoms.CLICK + "(locator)"); } else { parent.actionHandler.click(this, ""); } try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // This might be expected logger.fine("Response not received, returning control to user"); } }
private void assertElementDisplayed(String message) { Boolean displayed = parent.implicitlyWaitFor( new Callable<Boolean>() { public Boolean call() { return isDisplayed(); } }); if (displayed == null || !displayed) { throw new ElementNotVisibleException(message); } }
public OperaKeyboard(OperaDriver parent) { exec = parent.getScopeServices().getExec(); }
/** * Executes the given script with the element's object ID, but does not parse the response. * * @param script the script to execute */ private void executeMethod(String script) { parent.assertConnected(); debugger.callFunctionOnObject(script, objectId, false); }
/** * Calls the method and parses the result, the result must be a string * * @param method the method to call * @return response of EcmaScript in string presentation */ public final String callMethod(String method) { parent.assertConnected(); return debugger.callFunctionOnObject(method, objectId); }
protected List<WebElement> findElements(String by, String using) { return parent.findElements(by, using, this); }
protected WebElement findElement(String by, String using) { return parent.findElement(by, using, this); }
public void sendKeys(CharSequence... keysToSend) { // A list of keys that should be held down, instead of pressed ArrayList<String> holdKeys = new ArrayList<String>(); holdKeys.add(OperaKeys.SHIFT.getValue()); holdKeys.add(OperaKeys.CONTROL.getValue()); // Keys that have been held down, and need to be released ArrayList<String> heldKeys = new ArrayList<String>(); if (OperaFlags.ENABLE_CHECKS) { long start = System.currentTimeMillis(); boolean isDisplayed; while (true) { isDisplayed = isDisplayed(); if (!isDisplayed && parent.hasTimeRemaining(start)) { sleep(OperaIntervals.EXEC_SLEEP.getValue()); } else { break; } } assertElementDisplayed("Cannot type on an element that is not displayed"); assertElementEnabled("Cannot type on an element that is disabled"); } if (getTagName().equalsIgnoreCase("input") && (hasAttribute("type") && getAttribute("type").equals("file"))) { click(); } else { executeMethod("locator.focus()"); // When focused textareas return the cursor to the last position it was at. Inputs place the // cursor at the beginning, and so we need to move it to the end. We do this by pre-pending an // "End" key to the keys to send (in a round-about way). if (getTagName().equalsIgnoreCase("input")) { // Javascript from webdriver_session.cc in ChromeDriver executeMethod( "function(elem) {" + " var doc = elem.ownerDocument || elem;" + " var prevActiveElem = doc.activeElement;" + " if (elem != prevActiveElem && prevActiveElem)" + " prevActiveElem.blur();" + " elem.focus();" + " if (elem != prevActiveElem && elem.value && elem.value.length &&" + " elem.setSelectionRange) {" + " elem.setSelectionRange(elem.value.length, elem.value.length);" + " }" + " if (elem != doc.activeElement)" + " throw new Error('Failed to send keys because cannot focus element');" + "}(locator)"); } } // This code is a bit ugly. Because "special" keys can be sent either as an individual // argument, or in the middle of a string of "normal" characters, we have to loop through the // string and check each against a list of special keys. parent.getScopeServices().captureOperaIdle(); for (CharSequence seq : keysToSend) { if (seq instanceof Keys) { String key = OperaKeys.get(((Keys) seq).name()); // Check if this is a key we hold down, and haven't already pressed, and press, but don't // release it. That's done at the end of this method. if (holdKeys.contains(key) && !heldKeys.contains(key) && !execService.keyIsPressed(key)) { execService.key(key, false); heldKeys.add(key); } else if (key.equals("null")) { for (String hkey : heldKeys) { execService.key(hkey, true); } } else { execService.key(key); } } else if (seq.toString().equals("\n")) { execService.key("enter"); } else { // We need to check each character to see if it is a "special" key for (int i = 0; i < seq.length(); i++) { Character c = seq.charAt(i); String keyName = charToKeyName(c); // Buffer normal keys for a single type() call if (keyName == null) { execService.type(c.toString()); } else { String key = OperaKeys.get(keyName); // TODO: Code repeated from above if (holdKeys.contains(key) && !heldKeys.contains(key) && !execService.keyIsPressed(key)) { execService.key(key, false); heldKeys.add(key); } else if (key.equals("null")) { for (String hkey : heldKeys) { execService.key(hkey, true); } } else { execService.key(key); } } } } } if (heldKeys.size() > 0) { for (String key : heldKeys) { execService.key(key, true); } } try { parent.waitForLoadToComplete(); } catch (ResponseNotReceivedException e) { // This might be expected logger.fine("Response not received, returning control to user"); } // executeMethod("locator.blur()"); }