I have a webpage with a HTML table with some columns and rows. The user can select a row from the table and click the delete button. This will delete the row from the html table. E.g. In the Name column (index 1) there is a value "Testa" The user can select the checkbox for the row where Name is "Testa" and delete it.
I would like to iterate over the rows and check "Testa" is not there. This way I can be sure the delete worked.
My code is not iterating over the table.
My code snippet is:
def is_value_deleted_from_user_defined_field(self, name): # return true if the user defined name is null. This method is to verify the user defined field has been deleted
# Params name : The name of the user defined field e.g. AREACODE, Testa
try:
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, 'data_configuration_edit_data_object_tab_details_tb_fields')))
table_id = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, 'data_configuration_edit_data_object_tab_details_tb_fields')))
rows = table_id.find_elements(By.TAG_NAME, "tr")
for row in rows:
# Get the columns
col_name = row.find_elements(By.TAG_NAME, "td")[1] # This is the Name column
print "col_name.text = "
if (col_name.text != name):
return True
return False
except NoSuchElementException, e:
print "Element not found "
print e
self.save_screenshot("is_value_deleted_from_user_defined_field")
return False
My code to call the method is:
self.assertTrue(data_objects_edit_page.is_value_deleted_from_user_defined_field("Testa"), "User Defiend field Testa has not been deleted")
The HTML snippet is:
<table id="data_configuration_edit_data_object_tab_details_tb_fields" class="GFNQNVHJE border" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true">
<thead aria-hidden="false">
<colgroup>
<tbody style="">
<tr class="GFNQNVHCD GFNQNVHMD" __gwt_subrow="0" __gwt_row="0">
<td class="GFNQNVHBD GFNQNVHDD GFNQNVHED GFNQNVHLD GFNQNVHND">
<td class="GFNQNVHBD GFNQNVHDD GFNQNVHND">
<div __gwt_cell="cell-gwt-uid-407" style="outline-style:none;">
<input id="" class="" type="text" style="color: black;" value="AREACODE"/>
</div>
</td>
<td class="GFNQNVHBD GFNQNVHDD GFNQNVHND">
<div __gwt_cell="cell-gwt-uid-408" style="outline-style:none;">
<select tabindex="-1">
</div>
</td>
<td class="GFNQNVHBD GFNQNVHDD GFNQNVHOD GFNQNVHND">
<div __gwt_cell="cell-gwt-uid-409" style="outline-style:none;">
<input id="" class="" type="text" style="color: black;" value="50"/>
</div>
</td>
</tr>
<tr class="GFNQNVHCE GFNQNVHJD" __gwt_subrow="0" __gwt_row="1">
<td class="GFNQNVHBD GFNQNVHDE GFNQNVHED GFNQNVHKD">
<div __gwt_cell="cell-gwt-uid-406" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GFNQNVHBD GFNQNVHDE GFNQNVHKD">
<div __gwt_cell="cell-gwt-uid-407" style="outline-style:none;">
<input id="" class="" type="text" style="color: black;" value="VSEQ"/>
</div>
</td>
<td class="GFNQNVHBD GFNQNVHDE GFNQNVHKD">
<div __gwt_cell="cell-gwt-uid-408" style="outline-style:none;">
<select tabindex="-1">
<option value="Integer">Integer</option>
<option selected="selected" value="Text string">Text string</option>
<option value="Date/time">Date/time</option>
<option value="Floating point">Floating point</option>
</select>
</div>
</td>
<td class="GFNQNVHBD GFNQNVHDE GFNQNVHOD GFNQNVHKD">
</tr>
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;" aria-hidden="true"/>
</table>
The error I get is:
Traceback (most recent call last):
File "E:\test_runners 2 edit project - add more tests for Regression\selenium_regression_test_5_1_1\Regression_TestCase\RegressionProjectEdit_TestCase.py", line 951, in test_000033_Data_Objects_edit_ACVSEQ2_and_save_edited_changes
self.assertTrue(data_objects_edit_page.is_value_deleted_from_user_defined_field("Testa"), "User Defiend field Testa has not been deleted")
File "E:\test_runners 2 edit project - add more tests for Regression\selenium_regression_test_5_1_1\Pages\data_objects_edit.py", line 502, in is_value_deleted_from_user_defined_field
col_name = row.find_elements(By.TAG_NAME, "td")[1] # This is the Name column
IndexError: list index out of range
How do I iterate over the table and check "Testa" or for example "AREACODE" is not in the table? "AREACODE" is in the HTML snippet above. I think it is at index column 1
Thanks, Riaz