Example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated.

Prototype

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page and visible.

Usage

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

/**
 * Read the 60Days Graph data//from  w ww  . j  ava 2 s  .  c  o m
 */
protected void targetGraphData_60Days() {
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();

    handleLink_ByText(AppConstants.DAYS_60);
    Wait<WebDriver> wait = new WebDriverWait(getDriver(), 60);
    Map<String, String> mapbill = new HashMap<String, String>();
    jse.executeScript("window.scrollBy(0,-500)", "");
    jse.executeScript("window.scrollBy(0,225)", "");
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]")));
    //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 billcyclerootNodeXpath = "//*[name()='svg']/*[name()='g'][13]/*[name()='g'][1]";
    WebElement billcyclerootElement = getDriver().findElement(By.xpath(billcyclerootNodeXpath));

    String billcyclechildXpath = "./*[name()='text']";

    List<WebElement> listbillcyclechild = billcyclerootElement.findElements(By.xpath(billcyclechildXpath));

    int eleListSize = listbillcyclechild.size();
    // System.out.println("listChildElements.size() : " + listbillcyclechild.size());

    //Get the BillCycle Graph , tooltip Elements
    String bcGraphRootNodeXpath = "//*[name()='svg']/*[name()='g'][6]/*[name()='g']";
    WebElement bcGraphRootElement = getDriver().findElement(By.xpath(bcGraphRootNodeXpath));

    String bcGraphChildXpath = "./*[name()='g']";

    List<WebElement> listbcGraphChild = bcGraphRootElement.findElements(By.xpath(bcGraphChildXpath));
    int bcGraphListSize = listbcGraphChild.size();
    if (bcGraphListSize > 0) {
        targetBCGraphData_60Days = new HashMap();
    }
    // System.out.println("bcGraphListSize.size() : " + listbcGraphChild.size());

    for (int j = 0; j < eleListSize; j++) {
        int n = j + 1;
        Map<String, String> tempBCGData = new HashMap();
        String billCycleDate = null;
        String bcAtrribute_color = null;
        while (true) {
            breakIt = true;
            try {

                //read the billcycle data from nodes 
                String billchildNodePath_startDate = billcyclerootNodeXpath.concat("/*[name()='text']")
                        .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][1]"));
                WebElement billelement_startDate = getDriver()
                        .findElement(By.xpath(billchildNodePath_startDate));
                //Thread.sleep(2000);
                String billAtrribute_startDate = billelement_startDate.getText();

                String billchildNodePath_endDate = billcyclerootNodeXpath.concat("/*[name()='text']")
                        .concat("[").concat(String.valueOf(n).concat("]").concat("/*[name()='tspan'][2]"));
                WebElement billelement_endDate = getDriver().findElement(By.xpath(billchildNodePath_endDate));

                String billAtrribute_endDate = billelement_endDate.getText();

                billCycleDate = billAtrribute_startDate.concat("_").concat(billAtrribute_endDate);
                //System.out.println("Bill Cycle : '" + n+"' -->"+  billCycleDate);
                //read the billcycle graph data - color, tooltip from nodes
                String billchildNodePath_color = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[")
                        .concat(String.valueOf(n).concat("]").concat("/*[name()='path']"));
                //System.out.println("Node billchildNodePath_color : " + billchildNodePath_color);
                WebElement billelement_color = getDriver().findElement(By.xpath(billchildNodePath_color));

                bcAtrribute_color = billelement_color.getAttribute("stroke");
                String colorMap = AppConstants.COLOR.concat(AppConstants.BEGIN_BRACKET).concat(billCycleDate)
                        .concat(AppConstants.CLOSE_BRACKET);
                tempBCGData.put(colorMap, bcAtrribute_color);
                Actions builder = new Actions(getDriver());

                String childMouseHouverNode = bcGraphRootNodeXpath.concat("/*[name()='g']").concat("[")
                        .concat(String.valueOf(n).concat("]"));
                builder.moveToElement(getDriver().findElement(By.xpath(childMouseHouverNode))).perform();

                //System.out.println("childMouseHouverNode : '"+n +"' " +childMouseHouverNode);

                WebElement mouseHoverNodeElement = null;
                mouseHoverNodeElement = getDriver()
                        .findElement(By.xpath("//div[9]/div[1]/div[1]/div[2]/div/div/div"));
                //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[9]/div[1]/div[1]/div[2]/div/div/div")));

                if (mouseHoverNodeElement != null) {
                    String toolTipText = mouseHoverNodeElement.getText();
                    System.out.println("toolTipText : '" + n + "' " + toolTipText);
                    String toolTipTextMap = AppConstants.TOOL_TIP_TEXT.concat(AppConstants.BEGIN_BRACKET)
                            .concat(billCycleDate).concat(AppConstants.CLOSE_BRACKET);
                    tempBCGData.put(toolTipTextMap, toolTipText);
                    builder.moveToElement(getDriver().findElement(By.xpath(billchildNodePath_startDate)))
                            .click().perform();
                }

            } catch (Exception e) {
                if (e.getMessage().contains("element is not attached")) {
                    //System.out.println("Error: Element 4 ");
                    breakIt = false;
                }
            }
            if (breakIt) {
                break;
            }

        } //while loop ends
        targetBCGraphData_60Days.put(billCycleDate, tempBCGData);
    } //for loop ends
}

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

protected void targetTableData() {
    Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30);

    JavascriptExecutor jse = (JavascriptExecutor) getDriver();

    jse.executeScript("window.scrollBy(0,-800)", "");
    //getWebElement_By_xpath("//*[@id='content']/div[9]/div[1]/div[2]/ul/li["+(x+1)+"]").click();
    //handleLink_ByText(AppConstants.DAYS_60);
    jse.executeScript("window.scrollBy(0,800)", "");

    waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='details-table']")));

    WebElement headertable = getDriver().findElement(By.xpath("//*[@id='details-table']"));
    //int i=0;//from w  ww  .  j a v  a  2 s  .  c  om
    List<WebElement> header = headertable.findElements(By.xpath("//*[@id='billhistory']/tr"));

    System.out.println("===========Table Data========");
    // And iterate over them, getting the header data
    for (WebElement node : header) {
        List<WebElement> cells = node.findElements(By.tagName("th"));
        ;
        for (WebElement cell : cells) {

            headerList.add(cell.getText());
        }

        WebElement table = getDriver().findElement(By.xpath("//*[@id='details-table']/tbody"));
        List<WebElement> rows = table.findElements(By.tagName("tr"));
        // And iterate over them, getting the cells
        for (WebElement row : rows) {
            List<WebElement> rowcells = row.findElements(By.tagName("td"));

            for (WebElement cell : rowcells) {

                tableDataList.add(cell.getText());

            }
        }
    }
}

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)/* w  ww. ja va  2s.  c om*/
            .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  ww w.j  a  v  a2s  .  c om
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

/** Description: Testing the Plan Name
* Parameters: Not required//from w  w  w.j av a  2 s  .  c o m
* Return: No return
*/
protected void targetplanName() {
    try {
        waitgetForPageLoad(30)
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='plan-name']/strong")));
        String expectedPlanName = "Phoenix Project";
        actualPlanName = getWebElement_By_xpath("//*[@id='plan-name']/strong").getText();
        //System.out.println("Plan Name : "+ actualPlanName);
    } catch (Exception e) {
        log.error("Fail : To validate the target plan name");
    }

}

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

/** Description: Testing the Plan_ID
* Parameters:  Not required/*from w  w  w  .  jav  a2 s  . co  m*/
* Return: No return
*/
protected void targetplanId() {

    try {
        waitgetForPageLoad(30)
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='plan-detail']")));
        //String expectedPlanId = "413701757";
        actualPlanId = getWebElement_By_xpath("//*[@id='plan-detail']").getText();

        //System.out.println("Plan ID : "+ actualPlanId);
    } catch (Exception e) {
        log.error("Fail : To validate the target plan ID");
    }
}

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

/** Description: Testing the Total Reload
* Parameters:  Not required/*w w  w .j a v  a 2  s  .co m*/
* Return: No return
*/

protected void targetTotalReload() {
    try {

        waitgetForPageLoad(30).until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath("//*[@id='content']/div[9]/div[2]/div/div[1]/div[2]/p")));
        //String expectedTotalReload = "RM 0.00";
        actualTotalReload = getWebElement_By_xpath("//*[@id='content']/div[9]/div[2]/div/div[1]/div[2]/p")
                .getText();
        //System.out.println("Plan Name : "+ actualPlanName);
    } catch (Exception e) {
        log.error("Fail : To validate the target Total Reload");
    }

}

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

protected void targetFinalAmt() {
    WebDriverWait wait = new WebDriverWait(getDriver(), 20);
    try {// ww  w  .  ja  va 2s . co m
        //*[@id='content']/div/div/div[1]/div[9]/div[2]/strong
        wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//*[@id='content']/div/div/div[1]/div[9]/div[2]/strong")));
        WebElement amt = getDriver()
                .findElement(By.xpath("//*[@id='content']/div/div/div[1]/div[9]/div[2]/strong"));
        finalamt = amt.getText();
    } catch (Exception e) {
        log.error("Fail : To validate the targetAir time amount on Payment Page");
    }
}

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

/**
 * Reads Y_Axis Data for 30,60,90 days// w w  w. j av  a  2s .com
 * @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 returnAccountsPage() throws InterruptedException {
    tryToClickElementByXPath("//*[@id='menu-section']/div/ul/li[5]/a", 5).click();
    waitForPageLoad(100);//from ww w .j  ava2 s  .c o  m
    Thread.sleep(500);
    waitForPageLoad(60);
    Thread.sleep(500);
    log.info("Success : Returned back on accounts and payments page ");
    waitgetForPageLoad(30).until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='content']/div[13]/div/div")));
    getDriver().findElement(By.xpath("//*[@id='content']/div[13]/div/div/div[2]/button[1]")).click();
    waitForPageLoad(30);
}