/** Click top left, can be modified to click in the middle */
  public Point getLocation() {
    assertElementNotStale();

    String coordinates =
        debugger.callFunctionOnObject(
            "var coords = "
                + OperaAtom.GET_LOCATION
                + "(locator); return coords.x + ',' + coords.y;",
            objectId);

    // TODO: The goog.dom.getDocumentScrollElement_() function the Google closure library doesn't
    // return the document for SVG documents. This is used by the above atom. In this case the
    // coordinates string will be empty, so we use this fallback to get the coordinates. Hopefully
    // a fix will be forthcoming in the closure library.
    if (coordinates.isEmpty()) {
      logger.warning("Falling back to non-atom positioning code in getLocation");
      coordinates =
          debugger.callFunctionOnObject(
              "var coords = locator.getBoundingClientRect();"
                  + "return (coords.left-window.pageXOffset)+','+(coords.top-window.pageYOffset)",
              objectId);
    }

    String[] location = coordinates.split(",");
    return new Point(Integer.valueOf(location[0]), Integer.valueOf(location[1]));
  }
  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
    }
  }
Example #3
0
  /**
   * Initializes the services that are available.
   *
   * @param enableDebugger whether or not to enable the ecmascript-debugger service
   */
  private void initializeServices(boolean enableDebugger) {
    exec.init();
    windowManager.init();

    if (versions.containsKey("core") && coreUtils != null) {
      coreUtils.init();
    }

    if (versions.containsKey("prefs") && prefs != null) {
      prefs.init();
    }

    if (versions.containsKey("desktop-window-manager") && desktopWindowManager != null) {
      desktopWindowManager.init();
    }

    if (versions.containsKey("system-input") && systemInputManager != null) {
      systemInputManager.init();
    }

    if (versions.containsKey("desktop-utils") && desktopUtils != null) {
      desktopUtils.init();
    }

    if (enableDebugger) {
      debugger.init();
    }
  }
  private WebElement findSingleElement(String using, String type) {
    Integer id = debugger.executeScriptOnObject(using, objectId);
    if (id != null) {
      return new OperaWebElement(parent, id);
    }

    throw new NoSuchElementException("Cannot find element with " + type);
  }
 /**
  * @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();
 }
  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);
  }
 /**
  * @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());
 }
  public Dimension getSize() {
    assertElementNotStale();

    String widthAndHeight =
        debugger.callFunctionOnObject(
            "var s=" + OperaAtom.GET_SIZE + "(locator);return s.width+','+s.height;", objectId);

    String[] dimension = widthAndHeight.split(",");
    return new Dimension(Integer.valueOf(dimension[0]), Integer.valueOf(dimension[1]));
  }
 public Point getLocationInViewPort() {
   String coordinates =
       debugger.callFunctionOnObject(
           "locator.scrollIntoView();\n"
               + "var x = 0, y = 0;\n"
               + "if(window.top !== window.self) {\n"
               + "x = (window.screenLeft - window.top.screenLeft) + window.scrollX;\n"
               + "y = (window.screenTop - window.top.screenTop) + window.scrollY;\n"
               + "}\n"
               + "return (( x + locator.getBoundingClientRect().left) + ',' + ( y + locator.getBoundingClientRect().top));\n",
           objectId);
   String[] location = coordinates.split(",");
   return new Point(Integer.valueOf(location[0]), Integer.valueOf(location[1]));
 }
 /**
  * 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);
 }
 @Override
 protected void finalize() throws Throwable {
   debugger.releaseObject(objectId);
   super.finalize();
 }
 /**
  * Evaluates the given script with object ID, parses the result and returns the result object.
  *
  * @param script the script to execute
  * @return a parsed result object from the executor
  */
 private Object evaluateMethod(String script) {
   return debugger.callFunctionOnObject(script, objectId, true);
 }
Example #14
0
 /**
  * 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) {
   return debugger.callFunctionOnObject(method, objectId);
 }
Example #15
0
 /**
  * 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) {
   debugger.callFunctionOnObject(script, objectId, false);
 }