Hi Everyone!
I want to click on a date in a web-table where the dates can be or can’t be unique. If the dates are not unique then I should be able to click the first occurrence of that date and if the date is unique then it should click on it. Below is the sample table html:
Next Travel Date | Type | Amount |
---|---|---|
Apr. 11, 2024 | Cash | $666.00 |
Jun. 11, 2024 | Credit | $555.00 |
Apr. 11, 2024 | Cash | $666.00 |
This is my code:
*** Variables ***
${ExternalDate} Apr. 11, 2024
*** Test Cases ***
Click on Date in Table
Wait Until Page Contains Element xpath://table[@id='regularTravelExpense']
${date_elements} Get WebElements xpath://table[@id='regularInvestment']//td[@class='nextTravelDate']
${date_count} Get Length ${date_elements}
${date_found} Set Variable ${False}
${index} Set Variable ${-1}
FOR ${i} IN RANGE ${date_count}
${date} Get Text ${date_elements[${i}]}
Run Keyword If '${date}' == '${ExternalDate}' Run Keyword If '${date_found}' != '${True}' Run Keywords Set Variable ${date_found} ${True} AND Set Variable ${index} ${i} AND Exit For Loop
Run Keyword If '${date}' != '${ExternalDate}' Run Keywords Click Element ${date_elements[${i}]} AND Exit For Loop
END
Run Keyword If '${index}' != '-1' Run Keywords Click Element ${date_elements[${index}]} AND ELSE Log No matching date found.
The result I’m getting is: No matching date found
Can anyone guide me where I’m making mistake in my code?