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.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java

protected void targetEventDropdown() {

    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    jse.executeScript("window.scrollBy(0,175)", "");
    handleLink_ByText("90 Days");
    //       waitgetForPageLoad(30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("90 Days")));
    jse.executeScript("window.scrollBy(0,-800)", "");

    jse.executeScript("window.scrollBy(0,1000)", "");
    waitgetForPageLoad(30)/*from ww w .j a  v a2s. co  m*/
            .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='example-daterange']")));
    getDriver().findElement(By.xpath("//*[@id='example-daterange']")).click();
    waitgetForPageLoad(30)
            .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[3]/div")));
    getDriver().findElement(By.xpath("/html/body/div[3]/div/div[3]/button")).click();
    boolean breakIt;

    while (true) {
        breakIt = true;
        try {
            waitgetForPageLoad(30).until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//*[@id='tableview']/div/form/div/div[2]")));
            Select dropdown = new Select(getDriver().findElement(By.id("filterDescription")));
            String dropdownxpath = "//*[@id='filterDescription']/option";
            List<WebElement> dropdownelements = getDriver().findElements(By.xpath(dropdownxpath));
            System.out.println(dropdownelements.size());

            for (int i = 0; i < dropdownelements.size(); i++) {
                waitgetForPageLoad(30).until(ExpectedConditions.visibilityOfElementLocated(
                        By.xpath("//*[@id='filterDescription']/option[" + (i + 1) + "]")));
                dropdown.selectByIndex(i);
                System.out.println(dropdown.getOptions().get(i).getText());
                Thread.sleep(5000);
            }
            //waitgetForPageLoad(30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='filterDescription']/option[2]")));        
            //dropdown.selectByVisibleText("DSO"); 

            //System.out.println( dropdown.getFirstSelectedOption().getText()); 

        } catch (Exception e) {
            breakIt = false;
            e.printStackTrace();
        }
        if (breakIt) {
            break;
        }
    }
}

From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java

/**
 * Selects the month name from dropdown--showFilters
 *///from  w  w w  .j a v a 2s .co m
protected void targetdropdownmonths() {
    boolean breakIt;
    while (true) {
        breakIt = true;
        try {
            Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30);
            JavascriptExecutor jse = (JavascriptExecutor) getDriver();
            jse.executeScript("window.scrollBy(0,-800)", "");
            jse.executeScript("window.scrollBy(0,850)", "");
            waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='showFilters']")));
            getDriver().findElement(By.xpath("//*[@id='showFilters']")).click();
            dropdownmonths = getDriver().findElements(By.xpath("//*[@id='month-selector']/option"));
        } catch (Exception e) {
            breakIt = false;
        }
        if (breakIt) {
            break;
        }
    }
}

From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java

protected void target_reloadbtn() {
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    jse.executeScript("window.scrollBy(0,-800)", "");
    boolean breakIt;
    jse.executeScript("window.scrollBy(0,400)", "");
    while (true) {
        breakIt = true;//w w w.  j av a  2 s  .c  om
        try {
            WebElement reload = getDriver().findElement(By.linkText("Reload balance"));
            reload.click();
            log.info("Success: Reload button is clicked");
            waitForPageLoad(100);
        } catch (Exception e) {
            log.error("Fail : Failed to click on reload button");
            breakIt = false;
        }
        if (breakIt) {
            break;
        }
    }
}

From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java

protected void clickOnRadioRM50() {
    try {//from   www.ja  va  2  s .  c om

        // Put email id on text field as it can not be blank
        //*[@id="reloadForm__email"]
        WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email"));
        System.out.println(emailtxt.isEnabled());
        if (emailtxt.isEnabled()) {
            handleInputField_ByID("reloadForm__email", AppConstants.EMAIL);
            Thread.sleep(500);
        }
        JavascriptExecutor js1 = (JavascriptExecutor) getDriver();
        js1.executeScript("window.scrollBy(0,400)", "");
        //*[@id="prepaidReloadForm"]/ul/li[2]/label/div
        WebElement radio = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/ul/li[4]/label/div"));
        radio.click();
        // now select check box to accept license agreement
        WebElement checkbox = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/label/div"));
        checkbox.click();
        // click on proceed button after selecting radio button and check box
        // WebElement elementproceed=getDriver().findElement(By.xpath("//*[@id='proceedBtn']"));
        //*[@id="proceedBtn"]
        WebElement proceed = (new WebDriverWait(getDriver(), 1000))
                .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='proceedBtn']")));
        proceed.click();
        waitForPageLoad(100);
        Thread.sleep(500);
        JavascriptExecutor js = (JavascriptExecutor) getDriver();
        js.executeScript("window.scrollBy(0,500)", "");
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        log.error("Fail : Failed to Reload amount.");
        System.exit(0);

    }
}

From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java

/**
 * Reads Y_Axis Data for 30,60,90 days//ww  w .  j a  v a2s . co  m
 * @param index
 */

protected void getYAxisData(int index) {
    boolean breakIt = true;
    while (true) {
        breakIt = true;
        try {
            JavascriptExecutor jse = (JavascriptExecutor) getDriver();
            getWebElement_By_xpath("//div[9]/div[1]/div[2]/ul/li[" + index + "]/a").click();
            Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30);

            if (index == 1) {
                jse.executeScript("window.scrollBy(0,-210)", "");
                jse.executeScript("window.scrollBy(0,210)", "");
            }
            wait.until(ExpectedConditions.visibilityOfElementLocated(
                    By.xpath("//*[name()='svg']/*[name()='g'][13]/*[name()='g'][2]")));
            //Working :get the stroke attribute to get the color value of graph
            getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            //boolean breakIt = true;

            //Get the BillCycle Elements
            String yaxisrootNodeXpath = "//*[name()='svg']/*[name()='g'][13]/*[name()='g'][2]";
            WebElement yaxisrootElement = getDriver().findElement(By.xpath(yaxisrootNodeXpath));
            String yaxischildXpath = "./*[name()='text']";
            listyaxischild = yaxisrootElement.findElements(By.xpath(yaxischildXpath));
            int eleListSize = listyaxischild.size();
            // String targetrootdatapath= "//*[@id='content']/div[9]/div[1]/div[1]/div[2]/div/div/svg/g[13]/g[2]";
            if (index == 1)
                System.out.println("===========30 Days Y-AxisData========");
            else {
                if (index == 2)
                    System.out.println("===========60 Days Y-AxisData========");
                else
                    System.out.println("===========90 Days Y-AxisData========");
            }
        } //try ends
        catch (Exception e) {
            e.printStackTrace();
            breakIt = false;
        }
        if (breakIt) {
            break;
        }
    } //while loop ends
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void paymentPostpaidBroadband() throws InterruptedException {
    // try{/*w  ww.java2s.co m*/
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    jse.executeScript("window.scrollBy(0,-500)", "");
    //*[@id="planDetails"]/div[2]/div[1]/div[6]/button
    WebElement pay = tryToClickElementByXPath("//*[@id='planDetails']/div[2]/div[1]/div[6]/button", 5);
    pay.click();
    waitForPageLoad(30);
    log.info("Success: Make A Bill Payment button is clicked");
    Thread.sleep(2000);
    JavascriptExecutor jse1 = (JavascriptExecutor) getDriver();
    jse1.executeScript("window.scrollBy(0,300)", "");
    //*[@id="rp-form-field-payamount"]
    driver.findElement(By.id("rp-form-field-payamount")).clear();
    handleInputField_ByID("rp-form-field-payamount", AppConstants.RMVALUE);

    //Thread.sleep(500);
    //*[@id="proceed-button"]/span[1]
    WebElement payment = tryToClickElementByXPath("//*[@id='proceed-button']/span[1]", 5);
    payment.click();
    waitForPageLoad(20);
    Thread.sleep(2500);
    //WebElement payment2 = tryToClickElementByXPath("//*[@id='proceed-button']/span[1]", 5);
    payment.click();
    waitForPageLoad(30);
    Thread.sleep(2500);
    /*}
    catch(Exception e) {
       log.error("Fail : Failed to initialize Payment");
       e.printStackTrace();
       System.exit(0);
    }*/
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void paymentPostpaid() throws InterruptedException {
    // try{//from w w  w. ja v  a  2s . co  m
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    jse.executeScript("window.scrollBy(0,-500)", "");
    //*[@id="planDetails"]/div[2]/div[1]/div[6]/button
    WebElement pay = tryToClickElementByXPath("//*[@id='planDetails']/div[2]/div[1]/div[6]/button", 5);
    pay.click();
    waitForPageLoad(30);
    log.info("Success: Make A Bill Payment button is clicked");
    Thread.sleep(2000);
    JavascriptExecutor jse1 = (JavascriptExecutor) getDriver();
    jse1.executeScript("window.scrollBy(0,300)", "");
    //*[@id="rp-form-field-payamount"]
    driver.findElement(By.id("rp-form-field-payamount")).clear();
    handleInputField_ByID("rp-form-field-payamount", AppConstants.RMVALUE);

    //Thread.sleep(500);
    //*[@id="proceed-button"]/span[1]
    WebElement payment = tryToClickElementByXPath("//*[@id='proceed-button']/span[1]", 5);
    payment.click();
    waitForPageLoad(20);
    Thread.sleep(2500);
    //WebElement payment2 = tryToClickElementByXPath("//*[@id='proceed-button']/span[1]", 5);
    payment.click();
    waitForPageLoad(30);
    Thread.sleep(2500);
    /*}
    catch(Exception e) {
       log.error("Fail : Failed to initialize Payment");
       e.printStackTrace();
       System.exit(0);
    }*/

}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void cancelPaymentAndReturn() {
    // try {         
    //Back to Accounts & Plans
    JavascriptExecutor jse1 = (JavascriptExecutor) getDriver();
    jse1.executeScript("window.scrollBy(0,500)", "");
    WebElement cancel = tryToClickElementByXPath("//*[@id='pay-getaway-foot']/div[2]/button[3]", 5);
    cancel.click();/*www .j  av  a 2s.  co m*/
    waitForPageLoad(5);
    getDriver().switchTo().alert().accept();
    waitForPageLoad(30);

}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void clickOnRadio10() throws InterruptedException {
    // try {//  ww w  . ja va 2  s.c o m
    WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email"));
    System.out.println(emailtxt.isEnabled());
    if (emailtxt.isEnabled()) {
        handleInputField_ByID("reloadForm__email", AppConstants.EMAIL);
        //Thread.sleep(500);
    }
    JavascriptExecutor js1 = (JavascriptExecutor) getDriver();
    js1.executeScript("window.scrollBy(0,400)", "");

    tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[2]/label/div", 5).click();
    log.info("Success : Radio Button of amonut 10 is clicked");

    tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click();
    log.info("Success : checkbox is clicked");

    tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click();
    log.info("Success : Proceed Button is clicked");

    waitForPageLoad(100);
    Thread.sleep(500);
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    js.executeScript("window.scrollBy(0,500)", "");
    /*}catch(Exception e) {
       log.error("Fail : Failed to process reload of amount 10.");
       shutDown();
               
    }*/
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void clickOnRadio30() throws InterruptedException {
    // try {/*from w  w w. j av  a2  s  .  c  om*/
    WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email"));
    System.out.println(emailtxt.isEnabled());
    if (emailtxt.isEnabled()) {
        handleInputField_ByID("reloadForm__email", AppConstants.EMAIL);
        //Thread.sleep(500);
    }
    JavascriptExecutor js1 = (JavascriptExecutor) getDriver();
    js1.executeScript("window.scrollBy(0,400)", "");

    tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[3]/label/div", 5).click();
    log.info("Success : Radio Button of amonut 30 is clicked");

    tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click();
    log.info("Success : checkbox is clicked");

    tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click();
    log.info("Success : Proceed Button is clicked");

    waitForPageLoad(100);
    Thread.sleep(500);
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    js.executeScript("window.scrollBy(0,500)", "");
    /*}catch(Exception e) {
       log.error("Fail : Failed to process reload of amount 30.");
       shutDown();
               
    }*/
}