Example usage for org.openqa.selenium.support.ui Wait until

List of usage examples for org.openqa.selenium.support.ui Wait until

Introduction

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

Prototype

<T> T until(Function<? super F, T> isTrue);

Source Link

Document

Implementations should wait until the condition evaluates to a value that is neither null nor false.

Usage

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

private void jqueryWait() {
    Wait<WebDriver> wait = new WebDriverWait(driver(), 60);
    wait.until(jQueryReady());
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

public static void waitForPageLoad(WebDriver driver) {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);
    wait.until(new Function<WebDriver, Boolean>() {

        public Boolean apply(WebDriver driver) {
            //System.out.println("Current window state : " + String.valueOf(((JavascriptExecutor)driver).executeScript("return document.readyState")));
            return String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
                    .equals("complete");
        }//from www  . ja v  a  2s .com
    });
}

From source file:cc.kune.selenium.PageObject.java

License:GNU Affero Public License

/**
 * Checks if is element present./*from   w  w  w  . j av  a  2s .c o  m*/
 * 
 * @param id
 *          the id
 * @return true, if is element present
 */
public boolean isElementPresent(final String id) {
    final Wait<WebDriver> wait = new WebDriverWait(webdriver, 5);
    final WebElement element = wait.until(visibilityOfElementLocated(By.id(id)));
    return element != null;
}

From source file:com.coderoad.automation.common.util.old.BasePage.java

License:Open Source License

/**
 * Wait for page loaded.// ww w .j a  va  2 s  .c  o  m
 */
public void waitForPageLoaded() {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };

    Wait<WebDriver> wait = new WebDriverWait(this.getDriver(), TestUtils.timeout);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        LogUtil.log("Timeout waiting for Page Load Request to complete.", LogLevel.HIGH);
    }
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

public void waitForPageLoaded() {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }//w  w  w.j  a va 2 s .  co m
    };

    Wait<WebDriver> wait = new WebDriverWait(this.getDriver(), TestUtils.timeout);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        TestLogger.logError("Timeout waiting for Page Load Request to complete.");
    }
}

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

protected void targetYAxisData(int index) {

    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    jse.executeScript("window.scrollBy(0,-800)", "");

    getWebElement_By_xpath("//*[@id='content']/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)", "");
    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 {/* www.j  a  v  a 2 s. co m*/
        if (index == 2)
            System.out.println("===========60 Days Y-AxisData========");
        else
            System.out.println("===========90 Days Y-AxisData========");
    }
}

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

protected void targetTableData() {
    Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30);
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    //if(index>0)
    jse.executeScript("window.scrollBy(0,-800)", "");
    getWebElement_By_xpath("//*[@id='content']/div[9]/div[1]/div[2]/ul/li[1]").click();

    jse.executeScript("window.scrollBy(0,800)", "");
    waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='details-table']")));

    WebElement headertable = getDriver().findElement(By.xpath("//*[@id='details-table']"));
    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());
    }/*from   w  ww  . j av  a 2 s  .  co  m*/
    // Now get all the TR elements from the table
    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_Broadband_Util.java

/**
 * Read the 90Days Graph data// ww w  .  ja  v  a 2  s.c  o  m
 */
protected void targetGraphData_90Days() {
    Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30);
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();

    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]")));
    handleLink_ByText(AppConstants.DAYS_90);
    //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_90Days = 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();

                WebElement mouseHoverNodeElement = getDriver()
                        .findElement(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.replaceAll("\n", ""));
                    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_90Days.put(billCycleDate, tempBCGData);
    } //for loop ends
}

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

protected void targetGraphData_60Days() {
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();
    Wait<WebDriver> wait = new WebDriverWait(getDriver(), 30);
    jse.executeScript("window.scrollBy(0,-500)", "");
    jse.executeScript("window.scrollBy(0,225)", "");
    handleLink_ByText(AppConstants.DAYS_60);
    Map<String, String> mapbill = new HashMap<String, String>();

    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();
    }/*from ww  w .j a  va  2s.  c o  m*/
    // 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();

                WebElement mouseHoverNodeElement = getDriver()
                        .findElement(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_Broadband_Util.java

/**
 * Read the 30Days Graph data/*ww w .j  a  v a2s .com*/
 */
protected void targetGraphData_30Days() {
    JavascriptExecutor jse = (JavascriptExecutor) getDriver();

    Wait<WebDriver> wait = new WebDriverWait(getDriver(), 15);

    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]")));
    handleLink_ByText(AppConstants.DAYS_30);

    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_30Days = new HashMap();
    }
    // System.out.println("bcGraphListSize.size() : " + listbcGraphChild.size());

    for (int j = 0; j < eleListSize; j++) {
        int n = j + 1;
        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']"));
                WebElement billelement_Date = getDriver().findElement(By.xpath(billchildNodePath_startDate));

                billCycleDate = billelement_Date.getText();

                if ((billCycleDate.trim().length() > 0)
                        && (!(graphBillCycleDate_30Days.contains(billCycleDate)))) {
                    graphBillCycleDate_30Days.add(billCycleDate);
                    System.out.println("Bill Cycle : '" + n + "' -->" + billCycleDate);
                }

                //read the billcycle graph data - color  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");

                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();

                WebElement mouseHoverNodeElement = getDriver()
                        .findElement(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(Integer.toString(n)).concat(AppConstants.CLOSE_BRACKET);
                    if ((toolTipText.trim().length() > 0)
                            && (!(graphToolTipData_30Days.contains(toolTipText)))) {
                        graphToolTipData_30Days.add(toolTipText);
                        builder.moveToElement(getDriver().findElement(By.xpath(billcyclerootNodeXpath))).click()
                                .build().perform();
                        Thread.sleep(3000);
                    } //end if - tooltip text
                } //end if - mouseHoverNodeElement

            } catch (Exception e) {
                if (e.getMessage().contains("element is not attached")) {
                    breakIt = false;
                }
            }
            if (breakIt) {
                break;
            }

        } //while loop ends
        targetBCGraphData_30Days.put(Integer.toString(n), bcAtrribute_color);
    } //for loop ends
}