robotframework - 尝试使用追加到文件引发 AttributeError 异常
问题描述
我正在尝试将存储在变量中的数据附加到文件中。文件创建成功,数据存储在变量中;但是,我继续收到 AttiributeError:
AttributeError: 'NoneType' object has no attribute 'replace'
这是我的结果
KEYWORD ${FileA} = OperatingSystem . Create File metrics/Live_RTT.txt, ${MT_Com_RTT_LB_Live_Topics}
00:00:05.233 KEYWORD Selenium2Library . Click Element ${BLANK_CANVAS}
00:00:05.129 KEYWORD Selenium2Library . Click Element //div[@title='${device1}']
00:00:05.063 KEYWORD Selenium2Library . Click Element //div[@title='${device2}']
00:00:00.045 KEYWORD ${MT_Com_RTT_LB_Live_Topics} = Selenium2Library . Get Text xpath=${REAL_TIME_TRENDING_TOPICS}
00:00:00.001 KEYWORD BuiltIn . Log ${MT_Com_RTT_LB_Live_Topics}
Documentation:
Logs the given message with the given level.
Start / End / Elapsed: 20181028 21:37:34.971 / 20181028 21:37:34.972 / 00:00:00.001
21:37:34.971 INFO Available Topics
Active Energy Delivered + Received
Active Energy Into the Load
Active Energy Out of the Load
Active Power
Active Power A
00:00:00.001 KEYWORD OperatingSystem . Append To File ${FileA}, ${MT_Com_RTT_LB_Live_Topics}
Documentation:
Appends the given content to the specified file.
Start / End / Elapsed: 20181028 21:37:34.972 / 20181028 21:37:34.973 / 00:00:00.001
21:37:34.973 FAIL AttributeError: 'NoneType' object has no attribute 'replace'
解决方案
查看库的源代码,最有可能在方法中引发异常,该normalize_path()
方法执行此字符串替换:
path = os.path.normpath(os.path.expanduser(path.replace('/', os.sep)))
,文件名在哪里- kw 调用path
的第一个参数。Append To File
异常说它的值是None
(例如没有设置值),而它应该是一些字符串。
查看日志,您将此值设置为的返回值Create File
- 但该关键字根本不返回一个,它只是创建您在其第一个参数中指定的文件。
所以要解决 - 只需设置${FileA}
自己的值,将其传递给两个关键字,并且不要在Create File
调用中重新分配。
推荐阅读
- flutter - Flutter:Streambuilder被多次调用
- sql-server - 有没有按月和lineNum 重叠的求和函数?
- elasticsearch - 用于弹性搜索的 kubernetes statefulset-controller 特权初始化容器
- powerbi - 使用查询添加列时关系中断
- python-requests - 这是python36版本的问题吗?如何解决?
- bit-manipulation - Count leading zero bits for each element in AVX2 vector, emulate _mm256_lzcnt_epi32
- wordpress - 过滤器网格的 Wordpress 帖子视图格式
- c++ - 如何拥有可被多种语言调用的 C++ 库?
- hazelcast-jet - Hazelcast Jet - 将列表排到流中
- node.js - 如何将 JSON 值输入到我的 postgresql 数据库?