Search in sources :

Example 1 with RemoteWebElement

use of org.openqa.selenium.remote.RemoteWebElement in project ats-framework by Axway.

the class RealHtmlTable method getAllValues.

/**
     * Get the values of all table cells.</br>
     * 
     * <b>Note:</b> If a table cell contains a checkbox - we will return 'checked' or 'notchecked' value.
     * 
     * @return a two dimensional array containing all table cell values
     */
@PublicAtsApi
public String[][] getAllValues() {
    new RealHtmlElementState(this).waitToBecomeExisting();
    WebElement table = RealHtmlElementLocator.findElement(this);
    String scriptForHtml = generateScriptForGettingTableContent(".innerHTML");
    Object returnedHtmlValue = ((JavascriptExecutor) webDriver).executeScript(scriptForHtml, table);
    String scriptForObjects = generateScriptForGettingTableContent("");
    Object returnedObjectsValue = ((JavascriptExecutor) webDriver).executeScript(scriptForObjects, table);
    String[][] tableData = null;
    if (returnedHtmlValue != null && returnedHtmlValue instanceof List && returnedObjectsValue != null && returnedObjectsValue instanceof List) {
        List<?> htmlTable = (List<?>) returnedHtmlValue;
        List<?> objectsTable = (List<?>) returnedObjectsValue;
        // allocate space for a number of rows
        tableData = new String[htmlTable.size()][];
        for (int iRow = 0; iRow < htmlTable.size(); iRow++) {
            if (htmlTable.get(iRow) instanceof List) {
                List<?> htmlRow = (List<?>) htmlTable.get(iRow);
                List<?> objectsRow = (List<?>) objectsTable.get(iRow);
                // allocate space for the cells of the current row
                tableData[iRow] = new String[htmlRow.size()];
                for (int iColumn = 0; iColumn < htmlRow.size(); iColumn++) {
                    Object htmlWebElement = htmlRow.get(iColumn);
                    Object objectWebElement = objectsRow.get(iColumn);
                    // some data cannot be presented in textual way - for example a checkbox 
                    String htmlValueString = htmlWebElement.toString().toLowerCase().replace("\r", "").replace("\n", "");
                    if (htmlValueString.matches(".*<input.*type=.*[\"|']checkbox[\"|'].*>.*")) {
                        // We assume this is a checkbox inside a table cell.
                        // We will return either 'checked' or 'notchecked'
                        tableData[iRow][iColumn] = htmlValueString.contains("checked") ? "checked" : "notchecked";
                    } else {
                        // proceed in the regular way by returning the data visible to the user
                        tableData[iRow][iColumn] = ((RemoteWebElement) objectWebElement).getText();
                    }
                }
            }
        }
    } else {
        log.warn("We could not get the content of table declared as: " + this.toString());
    }
    return tableData;
}
Also used : RealHtmlElementState(com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) List(java.util.List) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)1 List (java.util.List)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebElement (org.openqa.selenium.WebElement)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1