Example usage for org.openqa.selenium JavascriptExecutor executeScript

List of usage examples for org.openqa.selenium JavascriptExecutor executeScript

Introduction

In this page you can find the example usage for org.openqa.selenium JavascriptExecutor executeScript.

Prototype

Object executeScript(String script, Object... args);

Source Link

Document

Executes JavaScript in the context of the currently selected frame or window.

Usage

From source file:org.eclipse.che.selenium.pageobject.FindAction.java

License:Open Source License

/**
 * try to get attribute checked from checkbox
 *
 * @return selected state checkbox of widget
 *//*from   ww  w.j a v  a  2  s .  c o  m*/
public boolean isCheckBoxSelected() {
    JavascriptExecutor js = (JavascriptExecutor) seleniumWebDriver;
    Object chkBoxObject = js.executeScript("return arguments[0].getAttribute(\"checked\");",
            includeNonMenuActions);
    return (chkBoxObject == null) ? false : Boolean.parseBoolean(chkBoxObject.toString());
}

From source file:org.eclipse.rap.selenium.RapBot.java

License:Open Source License

/**
 * Returns true while the RAP client is waiting for the server to process an event.
 *//*w w  w. j  av a  2s  .co  m*/
public boolean isRequestPending() {
    if (driver instanceof JavascriptExecutor) {
        String script = "return RapBot.busy;";
        JavascriptExecutor executer = (JavascriptExecutor) driver;
        return ((Boolean) executer.executeScript(script, (Object) null)).booleanValue();
    } else {
        throw new IllegalStateException("This driver does not support JavaScript execution.");
    }
}

From source file:org.finra.jtaf.ewd.widget.element.Element.java

License:Apache License

/***
 * Focus on this element// ww  w.  j  a  va2 s . c o m
 */
@Override
public void focusOn() throws WidgetException {
    WebDriver driver = SessionManager.getInstance().getCurrentSession().getWrappedDriver();
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    jse.executeScript("arguments[0].focus();", findElement());
}

From source file:org.jboss.arquillian.graphene.ftest.enricher.selenium.TestSeleniumResourceProvider.java

License:Open Source License

@Test
public void testJavaScriptExecutor(@ArquillianResource JavascriptExecutor executor) {
    executor.executeScript("document.title = arguments[0]", "New Title");
    assertEquals("New Title", browser.getTitle());
}

From source file:org.jboss.arquillian.graphene.ftest.webdriver.FindElementTestCase.java

License:Open Source License

@Test
public void testStelenessAndJavascriptOnWebDriver() {
    WebElement stale = browser.findElement(By.className("stale"));
    makeStale.click();//from  ww  w.jav  a 2s .  c  o  m
    JavascriptExecutor executor = (JavascriptExecutor) browser;
    installator.install();
    executor.executeScript("Graphene.jQuery(arguments[0]).trigger('blur')", stale);
}

From source file:org.jboss.arquillian.graphene.ftest.webdriver.FindElementTestCase.java

License:Open Source License

@Test
public void testStelenessAndJavascriptOnWebElement() {
    WebElement inStale = browser.findElement(By.className("stale")).findElement(By.className("in-stale"));
    makeStale.click();/*ww  w. j a  va 2s. c  o m*/
    JavascriptExecutor executor = (JavascriptExecutor) browser;
    installator.install();
    executor.executeScript("Graphene.jQuery(arguments[0]).trigger('blur')", inStale);
}

From source file:org.jboss.arquillian.graphene.javascript.JavaScriptUtils.java

License:Open Source License

public static Object execute(JavascriptExecutor executor, String javaScript, Object... args) {
    try {//from w  w  w .j  a va  2  s  . c  o m
        if (isAndroidDriver(executor)) {
            return executor.executeScript(javaScript.replace("\n", ""), args);
        } else {
            return executor.executeScript(javaScript, args);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.keycloak.testsuite.console.page.fragment.AbstractMultipleSelect2.java

License:Apache License

protected BiFunction<WebElement, R, Boolean> deselect() {
    return (selected, value) -> {
        WebElement selection = selected.findElements(By.tagName("div")).get(0);
        if (identity().apply(value).equals(selection.getText())) {
            WebElement element = selected
                    .findElement(By.xpath(".//a[contains(@class,'select2-search-choice-close')]"));
            JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", element);
            pause(500);/*from www.  j  a va2 s  .co m*/
            return true;
        }
        return false;
    };
}

From source file:org.keycloak.testsuite.console.page.fragment.SingleStringSelect2.java

License:Apache License

@Override
protected BiFunction<WebElement, String, Boolean> deselect() {
    return (selected, value) -> {
        if (identity().apply(value).equals(selected.getText())) {
            WebElement element = selected
                    .findElement(By.xpath(".//a[contains(@class,'select2-search-choice-close')]"));
            JavascriptExecutor executor = (JavascriptExecutor) getDriver();
            executor.executeScript("arguments[0].click();", element);
            WaitUtils.pause(500);/*from   w  w w .j  a va  2 s  .  c o m*/
            return true;
        }
        return false;
    };
}

From source file:org.kie.page.objects.KIEMenu.java

License:Apache License

private void clickMenu(WebElement menuItem) {
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", menuItem);
}