Reputation: 163
I want to click on the link which is present in the last column of a dynamic web table using Robot Framework. The scenario is that I've to verify the text in that web table and then click on its orderId. The text that I'm getting is from external source.
The RF code written is:
*** Test Cases ***
${p} Get File C:\\Users\\gaurav\\Desktop\\company.txt
log to console ${p}
Open Browser ${url} chrome
Maximize Browser Window
${s} wait until page contains ${p}
${elemnts} Get WebElements //div[@id="content"]//table//tbody/tr
@{links} Create List
:FOR ${row} IN @{elemnts}
\ Append To List ${links} ${row.text}
\ Log ${links}
\ Run Keyword IF '${s}' == 'True' Exit For Loop
\ Click Element //div[@id="content"]//table//tbody/tr/td[5]
I'm able to iterate through every row but it doesn't click on the orderId.
The company.txt file has the name Island Trading
Upvotes: 0
Views: 3006
Reputation: 13
You can try this
Keywords
Get Table Row Count
[Arguments] ${rowLocator}
run keyword and return get element count ${rowLocator}
Get Row By Cell Text
[Arguments] ${rowLocator} ${cellText} ${column}
[Return] ${rowNumber}
${rowCount} get table row count ${rowLocator}
:FOR ${rowIndex} IN RANGE 1 ${rowCount}+1
\ ${curText} get text ${rowLocator}[${rowIndex}]/td[${column}]
\ exit for loop if '${curText}'=='${cellText}'
${rowNumber} set variable ${rowIndex}
Once you get row index use that for click element passing to tag for xpath of the link.
Upvotes: 0