Package org.openqa.selenium

Examples of org.openqa.selenium.JavascriptExecutor


   * @throws CrawljaxException
   *             when javascript execution failed.
   */
  public Object executeJavaScript(String code) throws CrawljaxException {
    try {
      JavascriptExecutor js = (JavascriptExecutor) browser;
      return js.executeScript(code);
    } catch (WebDriverException e) {
      throwIfConnectionException(e);
      throw new CrawljaxException(e);
    }
  }
View Full Code Here


   *             when javascript execution failed.
   */
  @Override
  public Object executeJavaScript(String code) throws CrawljaxException {
    try {
      JavascriptExecutor js = (JavascriptExecutor) browser;
      return js.executeScript(code);
    } catch (WebDriverException e) {
      throwIfConnectionException(e);
      throw new CrawljaxException(e);
    }
  }
View Full Code Here

        }
        sb.append("req.setRequestHeader('Accept', 'application/json');\n");
        sb.append("req.send(null);\n");
        sb.append("return req.status + '///' + req.responseText;\n");

        JavascriptExecutor js = (JavascriptExecutor) driver;
        String response = (String) js.executeScript(sb.toString());
        return response.split("///");
    }
View Full Code Here

    @Override
    public void get(final String url) {
        driver.get(url);

        final JavascriptExecutor js = (JavascriptExecutor) driver;

        WebDriverUtils.waitForWindowJavaScriptVariableToBePresent(js, SAGA_NAMESPACE);

        new SafeJavascriptWait(js)
                .withTimeout(config.getBackgroundJavaScriptTimeout(), TimeUnit.MILLISECONDS)
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public Map<String, Map<String, Long>> extractCoverageDataVariable() {
        final JavascriptExecutor js = (JavascriptExecutor) driver;
        return (Map<String, Map<String, Long>>) js.executeScript("return window." + ScriptInstrumenter.COVERAGE_VARIABLE_NAME);
    }
View Full Code Here

     * Execute some Javascript in the underlying WebDriver driver.
     * @param script
     */
    public Object executeScript(final String script) {
        if (javascriptIsSupportedIn(driver)) {
            JavascriptExecutor js = getJavascriptEnabledDriver();
            return js.executeScript(script);
        } else {
            return null;
        }
    }
View Full Code Here

        }
    }

    public Object executeScript(final String script, final Object... params) {
        if (javascriptIsSupportedIn(driver)) {
            JavascriptExecutor js = getJavascriptEnabledDriver();
            return js.executeScript(script, params);
        } else {
            return null;
        }
    }
View Full Code Here

        String ckey = "cookiekey";
        String cval = "cookieval";

        WebDriver d = getDriver();
        d.get("http://www.google.com");
        JavascriptExecutor js = (JavascriptExecutor) d;

        // Of course, no cookie yet(!)
        Cookie c = d.manage().getCookieNamed(ckey);
        assertNull(c);

        // Attempt to create cookie on multiple Google domains
        js.executeScript("javascript:(" +
                "function() {" +
                "   cook = document.cookie;" +
                "   begin = cook.indexOf('"+ckey+"=');" +
                "   var val;" +
                "   if (begin !== -1) {" +
                "       var end = cook.indexOf(\";\",begin);" +
                "       if (end === -1)" +
                "           end=cook.length;" +
                "       val=cook.substring(begin+11,end);" +
                "   }" +
                "   val = ['"+cval+"'];" +
                "   if (val) {" +
                "       var d=Array('com','co.jp','ca','fr','de','co.uk','it','es','com.br');" +
                "       for (var i = 0; i < d.length; i++) {" +
                "           document.cookie = '"+ckey+"='+val+';path=/;domain=.google.'+d[i]+'; ';" +
                "       }" +
                "   }" +
                "})();");
        c = d.manage().getCookieNamed(ckey);
        assertNotNull(c);
        assertEquals(cval, c.getValue());

        // Set cookie as empty
        js.executeScript("javascript:(" +
                "function() {" +
                "   var d = Array('com','co.jp','ca','fr','de','co.uk','it','cn','es','com.br');" +
                "   for(var i = 0; i < d.length; i++) {" +
                "       document.cookie='"+ckey+"=;path=/;domain=.google.'+d[i]+'; ';" +
                "   }" +
View Full Code Here

      selenium = new WebDriverBackedSelenium(getDriver(), Config.inst().TEAMMATES_URL);

      /*
       * Chrome hack. Currently Chrome doesn't support confirm() yet. http://code.google.com/p/selenium/issues/detail?id=27
       */
      JavascriptExecutor js = (JavascriptExecutor) getDriver();
      js.executeScript("window.confirm = function(msg){ return true;};");

    } else {

      System.out.println("Using " + Config.inst().BROWSER);

View Full Code Here

     * Huy: I have no idea why the driver.switchTo().alert() approach doesn't work even in Firefox (it supposed to!). This is a workaround to press Yes in the confirmation box. Same for function
     * below for No.
     */

    // if (Config.inst().BROWSER.equals("chrome")) {
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    js.executeScript("window.confirm = function(msg){ return true;};");
    // }
  }
View Full Code Here

TOP

Related Classes of org.openqa.selenium.JavascriptExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.