I have written code to fetch data from UI(web page) and then converted that data into dictionary format using json.loads (where I hardcoded the data) but the values present in UI keeps on changing so can anyone help me how can I use the data which I’m fetching from UI as input and then convert that data into dictionary format
For example data present in UI is :
{‘Maintenance contract(0)’: ‘109 630 €’, ‘Recommended repairs(0)’: ‘0 €’, ‘Estimated(17)’: ‘15 695 €’, ‘Upgrade(0)’: ‘0 €’}
the integer values of above data keeps on changing format remains the same so I have used the code
*** Settings ***
Library String
Library Collections
*** Variables ***
*** Test Cases ***
Ashwini Convert Dict
&{input_dict}= Get Dict From App
Log ${input_dict}
&{output_dict}= Convert App Dict ${input_dict}
Log ${output_dict}
*** Keywords ***
Get Dict From App
${input_dict}= Evaluate json.loads(‘{“Maintenance contract(0)”: “109 630 €”, “Recommended repairs(0)”: “0 €”, “Estimated(17)”: “15 695 €”, “Upgrade(0)”: “0 €”}’) modules=json
[Return] ${input_dict}
Convert App Dict
[Arguments] ${input_dict}
&{output_dict}= Create Dictionary
FOR ${key} ${val} IN &{input_dict}
Log “${key} | ${val}”
# break apart the key
${keyx} = Replace String ${key} ) ${EMPTY}
# @{keyparts}= Get Regexp Matches "${key}" ([^\\(]*)\\(([^\\)]*)
@{keyparts}= Split String ${keyx} (
Log ${keyparts}
# make the value to a number
# first remove the €
${noero} = Replace String ${val} € ${EMPTY}
${num}= Convert To Integer ${noero}
&{val_dict}= Create Dictionary
Set To Dictionary ${val_dict} number ${keyparts[1]} price ${num}
Log ${val_dict}
Set To Dictionary ${output_dict} ${keyparts[0]} ${val_dict}
END
[Return] ${output_dict}
this code to get below output:
{‘Maintenance Contract’ : {‘number’ : ‘0’,‘price’:1747510},‘Recommended repairs’:{‘number’:‘1’,‘price’:3},‘Upgrade’:{‘number’:‘0’},‘Estimated’:{number’:‘247’,‘price’:366294}}
Now the issue is that integer data from UI keeps on changing so hardcoded data which is used in json.loads will not applicable for other accounts so I want to take input as UI fethed data and convert it into required format
Can anyone help me with the code I tried alot but unable to get required output