json - 接收错误:没有名称为 '${json_data}= | 的关键字 评价 | json.load(open(${json_file})) | json'找到
问题描述
机器人框架相对较新。在带有 Chrome 的 Windows 10 笔记本电脑上使用机器人 4.0.3。在资源文件的顶部加载 Selenium 和 JSON 库。
使用具有以下内容的 JSON 文件:
{
"first_name": "test",
"last_name": "user1",
"email": "test.user1@homelendingpal.com",
"company": "test company",
"phone": "919-123-4567",
"message": "test user 1 test message"
}
然后尝试使用资源机器人文件中的以下代码片段从中加载和提取值:
Click Submit Button
${json_data}= | Evaluate | json.load(open(${json_file})) | json
${name_first}= ${json_data["first_name"]}
Input Text //input[@id=input_1_1_3] $name_first
${name_last}= ${json_data["last_name"]}
Input Text //input[@id=input_1_1_6] $name_last
${email}= ${json_data["email"]}
Input Text //input[@id=input_1_2] $email
${company}= ${json_data["company"]}
Input Text //input[@id=input_1_6]
${phone}= ${json_data["phone"]}
Input Text //input[@id=input_1_3]
Click Element xpath=//select[@id=input_1_4]/option[@value=Bank]
${message}= ${json_data["message"]}
Click Element id=gform_submit_button_1
我已经尝试了多种格式来加载文件并从谷歌搜索机器人框架 json 返回的各种示例中访问其中的元素。机器人总是在评估/加载语句上失败,并在标题中显示错误消息。
解决方案
您似乎更喜欢管道分隔格式,但缺少前导管道。根据机器人框架用户指南,您总是需要前导管道字符才能工作。
或者,如果您不使用管道,则行上的每个元素之间至少需要 2 个空格。
例如
| Click Submit Button
| | ${json_data}= | Evaluate | json.load(open(${json_file})) | json
和
Click Submit Button
${json_data}= Evaluate json.load(open(${json_file})) json
会是正确的。
推荐阅读
- python - 如何将 pandas 数据框插入现有的 postgres sql 数据库?
- swift - 将变量添加到已保存的用户默认变量
- python - 如何将列与熊猫连接?
- javascript - 我怎么能以这种方式格式化这些数据?
- python - 如何在一个 PDF 中保存多个熊猫图
- asp.net-core - ASP.NET Core 3.1 的自定义身份验证处理程序授权失败?
- python - Twint Python 库导致搜索查询异常
- python - 多个文件到单个文件的符号链接
- c++ - 当 bWaitAll = true 时 WaitForMultipleObjects 和 2 个事件
- javascript - MDC 按钮波纹根本不绘制