Currently Im using this code to get text from each boxes in column
I want to use dictionary instead of list in my code
${text_List}= Create List #1st list
FOR ${list} IN RANGE 3 ${element_count}+1 #count depends on element present but it will be same as ${total_list_count} below
${list_text}= Get Text ${xpath}${list}
Append To List ${text_List} ${list_text}
END
#expected output= ['124', '1445', '1123', '456', '2354']
FOR ${element} IN RANGE 1 ${total_list_count}+1 #list count is same as ${text_List} 1st list count
@{Text_List} Create List
${web_elements}= Get WebElements ${xpath}
FOR ${ele} IN ${web_elements}
${element_txt}= Get Text ${ele}
Append To List ${Text_List} ${element_txt}
END
END
I tried with following code to use dictionary
*** Test Cases ***
Example Test Case
${text_dict}= Create Dictionary # Create an empty dictionary named ${text_dict}
FOR ${list} IN RANGE 3 ${element_count}+1
${list_text}= Get Text ${xpath}${list} # Get the text value of the ${list} element
Set To Dictionary ${text_dict} ${list_text} ${EMPTY} # Add the text value as key to the dictionary with an empty value
END
FOR ${element} IN RANGE 1 ${total_list_count}+1 # Loop through a range of values which is same as the count of elements in ${text_dict}
${web_elements}= Get WebElements ${xpath} # Get a list of web elements using an xpath expression
FOR ${ele} IN ${web_elements} # Loop through the web elements
${element_txt}= Get Text ${ele} # Get the text value of the web element
${key}= Get From Dictionary ${text_dict} ${element} # Get the key value from ${text_dict} using ${element} as index
Set To Dictionary ${text_dict} ${key} ${element_txt} # Set the value of the key in ${text_dict} with ${element_txt}
END
END
With above code got error as:
Dictionary does not contain key ‘1’
because of following line i think
${key}= Get From Dictionary ${text_dict} ${element}
I’m expecting output as
{'124': 'for loop text one by one for that column', '1445': 'for loop text one by one for next column', '1223': 'for loop text one by one for that next column', '456': 'for loop text one by one for that next column', '2354': 'for loop text one by one for that next column'}