Robot Framework provide some table handling keyword, one for get cell text, rest are for check point keyword,actually, it’s not enouth for us to handle table actions in script designing.
When we use Java or other languages to design script under Selenium Webdriver, we also need to customize class to implement relevant methods, such as, getTableRowCount, clickLinkInTableCell…..
But for Robot Framework, search from Google, seems there not a good solution,think about many ways,finally, find the below method to handle table actions, maybe it’s not the best way, anyway, it’s worked.
Get Table Row Count
We can use ‘Get Matching Xpath Count’ method to get table row count.
Here, the locator is the row(tr) locator rather than table locator, and need to use xpath.
Get Row By Cell Text
Based on ‘Get Table Row Count’ keyword, use for loop to judge text in which row, to Get Row By Cell Textget current row index/number.
Click Link In Table Cell
From ‘Get Row By Cell Text’, get the current row index, then we can the link in table cell.
Example And More
- We can use the customized method like the below way
Notes: we will get the below error if we define locator with prefix ‘xpath=’, i am not sure why, or maybe only happened on my laptop, so please don’t use the prefix when define tr locator.1
2
3InvalidSelectorException: Message: The given selector xpath=//table[contains(@id, 'calendar_tableview')]/tbody/tr is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression xpath=//table[contains(@id, 'calendar_tableview')]/tbody/tr because of the following error:
TypeError: The expression cannot be converted to return the specified type
Do more jobs
We can implement more actions based on the above major implementation, such as ‘Get Table Column Count’, ‘Select Checkbox In Table Cell’, ‘Select From List In Table Cell’………