How to use getXPathBase method of com.paypal.selion.platform.html.Table class

Best SeLion code snippet using com.paypal.selion.platform.html.Table.getXPathBase

Source:Table.java Github

copy

Full Screen

...91 dataStartIndex = 1;92 // check all the <tr>'s in the <tbody> until we find the 1st <tr> that has <td>'s. Then we know we have a93 // row where the data starts. If there are columns in the <tbody>, there will be <th>'s for those rows.94 List<WebElement> allRows = null;95 String xPath = getXPathBase() + "tr";96 try {97 allRows = HtmlElementUtils.locateElements(xPath);98 } catch (NoSuchElementException e) {99 // if there is no tr in this table, then the tbody must be empty, therefore columns are not in the tbody100 return 1;101 }102 if (allRows != null) {103 for (WebElement row : allRows) {104 if (!row.findElements(By.xpath("td")).isEmpty()) {105 break;106 }107 dataStartIndex++;108 }109 }110 }111 return dataStartIndex;112 }113 /**114 * Returns the number of rows in a table. This will include the column row if that is the 1st row of the tbody.115 * 116 * @return int number of rows117 */118 public int getNumberOfRows() {119 String xPath = getXPathBase() + "tr";120 return HtmlElementUtils.locateElements(xPath).size();121 }122 /**123 * Returns the number of columns in a table. If the table is empty, column count cannot be determined and 0 will be124 * returned.125 * 126 * @return int number of columns127 */128 public int getNumberOfColumns() {129 List<WebElement> cells;130 String xPath = getXPathBase() + "tr";131 List<WebElement> elements = HtmlElementUtils.locateElements(xPath);132 if (elements.size() > 0 && getDataStartIndex() - 1 < elements.size()) {133 cells = elements.get(getDataStartIndex() - 1).findElements(By.xpath("td"));134 return cells.size();135 }136 return 0;137 }138 /**139 * Searches all rows from a table for the occurrence of the input search strings and returns the index to the row140 * containing all the search strings. The search will NOT be performed on the column's row(s).<br>141 * <br>142 * <b>Usage:</b>143 * 144 * <pre>145 * String[] search = { &quot;Payment To&quot;, &quot;-$7.00 USD&quot; };146 * int searchRow = findRowNumber(search);147 * </pre>148 * 149 * @param searchKeys150 * String[] array with as many values as need to identify the row151 * @return int number of first row where all conditions were met <br>152 * Negative number indicates that row was not found153 */154 public int getRowIndex(String[] searchKeys) {155 int numKey = searchKeys.length;156 int rowCount = getNumberOfRows();157 String xPathBase, xPath, value;158 xPathBase = getXPathBase();159 int rowIndex = -1;160 for (int i = getDataStartIndex(); i <= rowCount; i++) {161 xPath = xPathBase + "tr[" + i + "]";162 // get table row as text163 value = HtmlElementUtils.locateElement(xPath).getText();164 // search the table row for the key words165 if (value.length() > 0) {166 for (int s = 0; s < numKey; s++) {167 if (searchKeys[s] != null && ((String) searchKeys[s]).length() > 0) {168 if (value.contains((CharSequence) searchKeys[s])) {169 rowIndex = i;170 } else {171 rowIndex = -1;172 break;173 }174 }175 }176 }177 if (rowIndex > 0) {178 break;179 }180 }181 return rowIndex;182 }183 /**184 * Finds value of a cell in a table indicated by row and column indices. <br/>185 * <br/>186 * 187 * @param row188 * int number of row for cell189 * @param column190 * int number of column for cell191 * @return String value of cell with row and column. Null if cannot be found.192 */193 public String getValueFromCell(int row, int column) {194 if (row < 1 || column < 1) {195 throw new IllegalArgumentException("Row and column must start from 1");196 }197 List<WebElement> elements = HtmlElementUtils.locateElements(getXPathBase() + "tr");198 List<WebElement> cells = elements.get(row - 1).findElements(By.xpath(".//td"));199 if (cells.size() > 0) {200 return cells.get(column - 1).getText();201 }202 return null;203 }204 /**205 * Goes to the cell addressed by row and column indices and clicks link in that cell. Performs wait until page would206 * be loaded207 * 208 * @param row209 * int number of row for cell210 * @param column211 * int number of column for cell212 */213 public void clickLinkInCell(int row, int column) {214 String xPath = getXPathBase() + "tr[" + row + "]/td[" + column + "]/a";215 new Link(xPath).click();216 }217 /**218 * Generates xPath from element locator and path to the row (&lt;tr&gt; tag)<br>219 * Checks if table has &lt;TBODY&gt; tag and adds it to the xPath<br>220 * 221 * @return String with beginning of xPath<br>222 */223 public String getXPathBase() {224 String xPathBase = "";225 if (this.getElement() != null) {226 String locator = getLocator();227 if (!locator.startsWith("link=") && !locator.startsWith("xpath=") && !locator.startsWith("/")) {228 if (locator.startsWith("id=") || locator.startsWith("name=")) {229 String tmp = locator.substring(locator.indexOf('=', 1) + 1);230 if (locator.startsWith("id=")) {231 xPathBase = "//table[@id='" + tmp + "']/tbody/";232 } else {233 xPathBase = "//*[@name='" + tmp + "']/tbody/";234 }235 } else {236 xPathBase = "//*[@id='" + locator + "']/tbody/";237 }238 } else {239 if (locator.startsWith("xpath=")) {240 locator = locator.substring(locator.indexOf('=', 1) + 1);241 }242 if (HtmlElementUtils.locateElements(locator + "/tbody").size() > 0) {243 xPathBase = locator + "/tbody/";244 } else {245 xPathBase = locator + "//";246 }247 }248 } else {249 throw new NoSuchElementException("Table" + this.getLocator() + " does not exist.");250 }251 return xPathBase;252 }253 /**254 * Returns the single row of a table as a long string of text using the input row index.255 * 256 * @param rowIndex257 * the index to the row which text is about to retrieve.258 * @return rowText a text string represents the single row of a table259 */260 public String getRowText(int rowIndex) {261 String rowText = null;262 String xPath = getXPathBase() + "tr[" + rowIndex + "]";263 rowText = HtmlElementUtils.locateElement(xPath).getText();264 return rowText;265 }266 /**267 * Tick the checkbox in a cell of a table indicated by input row and column indices268 * 269 * @param row270 * int number of row for cell271 * @param column272 * int number of column for cell273 */274 public void checkCheckboxInCell(int row, int column) {275 String checkboxLocator = getXPathBase() + "tr[" + row + "]/td[" + column + "]/input";276 CheckBox cb = new CheckBox(checkboxLocator);277 cb.check();278 }279 /**280 * Untick a checkbox in a cell of a table indicated by the input row and column indices.281 * 282 * @param row283 * int number of row for cell284 * @param column285 * int number of column for cell286 */287 public void uncheckCheckboxInCell(int row, int column) {288 String checkboxLocator = getXPathBase() + "tr[" + row + "]/td[" + column + "]/input";289 CheckBox cb = new CheckBox(checkboxLocator);290 cb.uncheck();291 }292}...

Full Screen

Full Screen

getXPathBase

Using AI Code Generation

copy

Full Screen

1Table table = new Table("xpath of table");2String xPathBase = table.getXPathBase();3Table table = new Table("xpath of table");4String xPathBase = table.getXPathBase();5Table table = new Table("xpath of table");6String xPathBase = table.getXPathBase();7Table table = new Table("xpath of table");8String xPathBase = table.getXPathBase();9Table table = new Table("xpath of table");10String xPathBase = table.getXPathBase();11Table table = new Table("xpath of table");12String xPathBase = table.getXPathBase();13Table table = new Table("xpath of table");14String xPathBase = table.getXPathBase();15Table table = new Table("xpath of table");16String xPathBase = table.getXPathBase();17Table table = new Table("xpath of table");18String xPathBase = table.getXPathBase();19Table table = new Table("xpath of table");20String xPathBase = table.getXPathBase();21Table table = new Table("xpath of table");22String xPathBase = table.getXPathBase();23Table table = new Table("xpath of table");24String xPathBase = table.getXPathBase();25Table table = new Table("xpath of table");26String xPathBase = table.getXPathBase();

Full Screen

Full Screen

getXPathBase

Using AI Code Generation

copy

Full Screen

1String xpathBase = table.getXPathBase();2System.out.println(xpathBase);3System.out.println(table.getXPathBase());4System.out.println(table.getXPathBase());5System.out.println(table.getXPathBase());6System.out.println(table.getXPathBase());7System.out.println(table.getXPathBase());8System.out.println(table.getXPathBase());9System.out.println(table.getXPathBase());10System.out.println(table.getXPathBase());11System.out.println(table.getXPathBase());12System.out.println(table.getXPathBase());13System.out.println(table.getXPathBase());14System.out.println(table.getXPathBase());

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeLion automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful