Home > Software engineering >  Get the row of a webtable after 'Table Column Should Contain' in robot framework
Get the row of a webtable after 'Table Column Should Contain' in robot framework

Time:11-30

I have the next question about webtable handling over Robot Framework with selenium:

the webpage has a table with 3 columns, but the rows are variable based on the months of a year, I already use the 'Table Column Should Contain' to confirm the existence of a row with the text of a month (i.e. 'monthA'), but now I need to work with the adjacent cells based on that row

Column A Column B Column C
monthA orderA link A
monthB orderB link B

so far I'm trying to get a list of the available rows with

${rows}=    Get Element Count    //*[@id="root"]/div[2]/div/div[2]/div[9]/div/table/tbody/tr 

which gives me back the number of rows, but when I try to use it in a FOR cycle to get the names and the corresponding row, the index doesn't work, and looks like it doesn't recognize the value 0 of the index, the operation I try to do in the cycle is

${value}    Get Text    (//*[@id="root"]/div[2]/div/div[2]/div[9]/div/table/tbody/tr)[${i}]

enter image description here

for now I'm stuck in that part trying to figure how to make the index work

CodePudding user response:

Try to use FOR loop with Range starting from 1 so that index will point to row 1

 FOR    ${i}    IN RANGE    1    ${rows} 1
  ${value} =     Get Text    (//*@id="root"]/div[2]/div/div[2]/div[9]/div/table/tbody/tr)[${i}]
  Log   Month name is ${value}
  ${Order_name}= Get Text    //*@id="root"]/div[2]/div/div[2]/div[9]/div/table/tbody/tr[${i}]/td[2]
  Log   Order name is ${Order_name}
  < similarly you can do it for adjacent column>

 END

To get

CodePudding user response:

i ended using a for like was suggested by Rakesh, then i had to make it add a value compatible with the table, since it counts the heads as rows

${rowcount}    Evaluate    ${i}   3  

then a new FOR to evaluate each cell:

${value}    Run Keyword And Return Status    Table Cell Should Contain    //*[@id="root"]/div[2]/div/div[2]/div[9]/div/table    ${rowcount}    1    ${month_string}
    IF    ${value} == ${True}
        ${declaracion_status}    Run Keyword And Return Status    Table Cell Should Contain    //*[@id="root"]/div[2]/div/div[2]/div[9]/div/table    ${rowcount}    2    *Expected value*
        

Now, i have another issue, wich is rescuing the third cell wich contains a button, so technically should work with a 'Click Button' keyword, but i need to generate the correct xpath to it. in sctructure should be like this:

(//*[@id="root"]/div[2]/div/div[2]/div[9]/div/table/tbody/tr)([${rowvalue_xpath}])(/td[3]/button)

but the literal expression can't be used directly by the mentioned keyword since isn't a literal xpath

  • Related