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:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * The function will search for the element and then click on it using
 * the Click method of java script.//from w  ww.  ja  v a 2  s .c  o m
 *
 * @param driver
 * @param locator
 */
public void ClickJS(WebDriver driver, By locator) {
    this.log.debug("ClickJS::Enter");
    this.log.debug("Locator: " + locator.toString());

    WebElement element = WaitForElementPresenceAndVisible(driver, locator);
    if (element != null) {
        try {
            JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", element);
        } catch (WebDriverException wde) {
            if (wde.getMessage().contains("arguments[0].click is not a function")) {
                element.click();
            }
        }
    } else {
        this.log.error("Element is null " + locator.toString());
    }

    this.log.debug("ClickJS::Exit");
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * The function will search for the element present (doesn't matter
 * if element is visible or not) and then click on it.
 *
 * @param driver/* w ww . jav  a2 s  .co m*/
 * @param locator
 */
public void ClickElementInvisible(WebDriver driver, By locator) {
    this.log.debug("ClickElementInvisible::Enter");
    this.log.debug("Locator: " + locator.toString());

    WebElement element = FindElementInvisible(driver, locator);
    if (element != null) {
        try {
            JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", element);
        } catch (WebDriverException wde) {
            if (wde.getMessage().contains("arguments[0].click is not a function")) {
                element.click();
            }
        }
    } else {
        this.log.error("Element is null " + locator.toString());
    }

    this.log.debug("ClickElementInvisible::Exit");
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * The method shall move mouse over the element and fire the event
 * onclick when clicking on the element.
 * //from   w w w. j  a  v  a  2 s .com
 * @param driver
 * @param locator
 */
public void MouseOverElementAndClick(final WebDriver driver, final By locator) {
    this.log.debug("MouseOverElementAndClick::Enter");
    WebElement elementToOver = WaitForElementPresenceAndVisible(driver, locator);
    if (elementToOver != null) {
        String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
        String onClickScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onclick');}";

        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript(mouseOverScript, elementToOver);
        js.executeScript(onClickScript, elementToOver);
    } else {
        this.log.warn("Element null!");
    }
    this.log.debug("MouseOverElementAndClick::Exit");
}

From source file:com.pentaho.qa.gui.web.puc.BasePage.java

/**
 * Gets the property value of the specified element's CSS pseudo-element.
 * //www . j  a  v a  2s  . c  o  m
 * @param element
 *          The element that contains a pseudo element.
 * @param property
 *          The name of the property to retrieve the value from.
 * @param pseudoElement
 *          The name of the pseudo-element (i.e. "after" or "before").
 * @return Returns the value of the pseudo-element's property.
 */
private String getPseudoElementPropretyValue(WebElement element, String property, String pseudoElement) {
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    return executor.executeScript("return window.getComputedStyle(arguments[0], ':" + pseudoElement
            + "').getPropertyValue('" + property + "');", element).toString();
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public void clickManageWorkflows() {
    Util.waitForElement(driver, manageWorkflows, 10);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", manageWorkflows);
    Util.waitForLoaderToFinish(driver);
    Util.waitForAJAX(driver);/*from  w w  w . j av  a  2s  .com*/
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public void clickTeamRoles() {
    Util.waitForElement(driver, teamRoles, 10);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", teamRoles);
    Util.waitForAJAX(driver);//from w ww .  j a  va  2  s . c  om
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public void clickChecklistSummary() {
    Util.waitForElement(driver, teamRoles, 10);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", chklistSummary);
    Util.waitForAJAX(driver);//  www  .ja va  2 s .  c  o m
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public void clickAddBtnOnWorkflowSummary() {
    Util.waitForElement(driver, addOnManageWorkflows1, 10);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", addOnManageWorkflows1);
    Util.waitForAJAX(driver);/*  w  ww  . ja  va2 s.c o  m*/
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public void clickSecuritySettings() throws InterruptedException {
    Thread.sleep(2000);//from  www  . ja  v a  2 s  . c  o m
    Util.waitForAJAX(driver);
    Util.waitForElementPresent(driver, By.xpath("//*[@id='left']/div/div/ul/li[18]/a/span"), 10);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", securitySettings);

    Util.waitForAJAX(driver);
    Util.waitForLoaderToFinish(driver);
}

From source file:com.provenir.automation.framework.helper.AdminPage.java

public boolean verifyMandatoryDetailsOnManageWorkflow() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click();", saveWorkflow);
    if (errMsgOnManageWorkflow.isDisplayed()) {
        return true;
    } else//from w w  w.j a  va  2 s .  co  m
        return false;
}