Table Assertions
Learn how to assert a table using Selenium.
We'll cover the following...
Assert table text
HTML tables are commonly used for displaying grid data on web pages.
The source code for above HTML table is as follows:
Press + to interact
<table id="aha_table" cellpadding="1" border="1" width="30%"><tr id="row_1"><td id="cell_1_1">A</td><td id="cell_1_2">B</td></tr><tr id="row_2"><td id="cell_2_1">a</td><td id="cell_2_2">b</td></tr></table>
We can assert the text in this table as:
Press + to interact
driver.findElement(By.id("alpha_table")).getText().then(function(the_elem_text){assert.equal("A B\na b", the_elem_text);});driver.findElement(By.id("alpha_table")).then(function(the_element) {driver.executeScript("return arguments[0].outerHTML;", the_element).then(function(the_elem_html) {assert(the_element_html.contains("<td id=\"cell_1_1\">A</td>"))});});
The above script is asserting the text of the first table cell, ...