Example usage for org.openqa.selenium WebElement click

List of usage examples for org.openqa.selenium WebElement click

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement click.

Prototype

void click();

Source Link

Document

Click this element.

Usage

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

/** Reads the header data after selecting
 * different options from dropdown list/*from   w ww. j  ava 2  s.c om*/
 **/
protected void targetTableEventData() throws InterruptedException {
    Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30);
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    List<WebElement> speechbubble = null;

    boolean breakit;
    while (true) {
        breakit = true;
        try {

            getWebElement_By_xpath("//*[@id='content']/div[9]/div[1]/div[2]/ul/li[2]/a").click();
            jse.executeScript("window.scrollBy(0,240)", "");
            waittable
                    .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='details-table']")));

            getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            speechbubble = getDriver().findElements(By.xpath("//*[@id='column-filter-1']/ul/li"));
            System.out.println("Number of ChildNodes :" + speechbubble.size());
        } catch (Exception e) {
            //e.printStackTrace();
            breakit = false;
        }
        if (breakit == true) {
            break;
        }
    }
    //jse.executeScript("window.scrollBy(0,100)", "");    

    // Map<String,List<String>> testHeaderMap = new HashMap <String,List<String>>();
    //List<String> lsheaderTableKey = new ArrayList<String>() ; 
    List<String> lsheaderdata = null;
    int speechbubbleSize = speechbubble.size();
    String arHeaderKey[] = new String[speechbubbleSize];

    String headerKeyStr = "";
    for (int k = 0; k < speechbubbleSize; k++) {
        while (true) {
            breakit = true;
            try {
                jse.executeScript("window.scrollBy(0,50)", "");

                //click the dropdown control
                waittable.until(ExpectedConditions
                        .visibilityOfElementLocated(By.xpath("//*[@id='column-filter-sb']/span[2]")));
                getDriver().findElement(By.xpath("//*[@id='column-filter-sb']/span[2]")).click();

                int j = k + 1;

                String nodepath = "//*[@id='column-filter-1']/ul/li" + "[" + j + "]" + "/label";
                waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(nodepath)));
                WebElement childElementSub = getDriver().findElement(By.xpath(nodepath));
                System.out.println("Id :'" + j + "' " + childElementSub.getText());
                String headertableKey = childElementSub.getText();
                //lsheaderTableKey.add(headertableKey);
                headerKeyStr = headerKeyStr + headertableKey + AppConstants.COMMA;
                childElementSub.click(); //click the checkbox

                //click the update button
                waittable.until(ExpectedConditions
                        .visibilityOfElementLocated(By.xpath("//*[@id='speechBubble']/div[3]/button")));
                getDriver().findElement(By.xpath("//*[@id='speechBubble']/div[3]/button")).click();
                getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                //System.out.println("Id :'" +j+"' Update Button Clicked" );

                //Read the bill history table header data - begin
                waittable.until(
                        ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='details-table']")));
                WebElement headertable = getDriver().findElement(By.xpath("//*[@id='details-table']"));
                int i = 0;
                waittable.until(
                        ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='billhistory']/tr")));
                List<WebElement> header = headertable.findElements(By.xpath("//*[@id='billhistory']/tr"));

                // And iterate over them, getting the header data
                for (WebElement node : header) {
                    List<WebElement> cells = node.findElements(By.tagName("th"));
                    lsheaderdata = new ArrayList<String>();
                    for (WebElement cell : cells) {
                        //System.out.println("header"+cell.getText());
                        String headerData = cell.getText();
                        lsheaderdata.add(headerData);
                    }
                }

                //Read the bill history table header data - ends

                jse.executeScript("window.scrollBy(0,-50)", "");
            } catch (Exception e) {
                //e.printStackTrace();
                breakit = false;
            }
            if (breakit == true) {
                int indexPos = headerKeyStr.lastIndexOf(AppConstants.COMMA);
                String data = headerKeyStr.substring(0, indexPos);
                arHeaderKey[k] = data;
                System.out.println("lsheaderTableKey : " + data);
                dropDownTableHeaderMap.put(arHeaderKey[k], lsheaderdata);
                break;
            }
        } //end  while
    } //end for

    System.out.println("DropDown Control Data : " + dropDownTableHeaderMap);

}

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  a v a2  s .c  o  m
        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  ww  w. j  av  a2  s .  com*/

        // 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.common.PageNavigation.java

protected void paymentPostpaidBroadband() throws InterruptedException {
    // try{//from w  ww .ja va  2s.c  o 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 ww . j  ava2 s .  c o 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();
    waitForPageLoad(5);//w  w w.j a v  a 2 s.c o  m
    getDriver().switchTo().alert().accept();
    waitForPageLoad(30);

}

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

protected void reloadBroadband() throws InterruptedException {
    WebElement reload = tryToClickElementByXPath("//*[@id='planDetails']/div[2]/div[1]/div[5]/a", 5);
    reload.click();
    waitForPageLoad(30);//from w  w w .ja v  a2  s.co  m
    log.info("Success: Reload button is clicked");
    Thread.sleep(2000);
}

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

protected void reload1() throws InterruptedException {
    //*[@id="planDetails"]/div[2]/div[1]/div[4]/a
    //*[@id="planDetails"]/div[2]/div[1]/div[5]/a
    WebElement reload = tryToClickElementByXPath("//*[@id='planDetails']/div[2]/div[1]/div[5]/a", 5);
    reload.click();
    waitForPageLoad(30);/*from w w w  .  j a  v a  2  s. c om*/
    log.info("Success: Reload button is clicked");
    Thread.sleep(2000);
}

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

protected void clickCancel() throws InterruptedException {

    tryToClickElementByXPath("//*[@id='pay-getaway-foot']/div[2]/form/button[3]", 5).click();
    Thread.sleep(500);//from   w ww  .  j  a  va  2  s  . c  o m
    driver.switchTo().alert().accept();
    waitForPageLoad(60);
    Thread.sleep(500);
    log.info("Success : Payment is cancelled ");

    List<WebElement> element = getDriver().findElements(By.linkText("Back"));

    //boolean isPresent=getDriver().findElements(By.linkText("Back")).size()>0;
    if (element.size() > 0) {
        WebElement cancelpopup = element.get(0);
        cancelpopup.click();
    }
    //driver.switchTo().window(parent);
    waitForPageLoad(30);
    Thread.sleep(500);
}

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

protected void clickOnRadioRM25Broadband() {
    try {//  w w  w. j a  v  a  2s .  c  o m

        WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email"));
        if (emailtxt.isDisplayed()) {
            handleInputField_ByID("reloadForm__email", AppConstants.EMAIL);
            Thread.sleep(500);
        }
        JavascriptExecutor js1 = (JavascriptExecutor) getDriver();
        js1.executeScript("window.scrollBy(0,400)", "");
        WebElement radio = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/ul/li[5]/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(driver, 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);
    }

}