我尝试从txt文件中获取变量${var_Master}
并将其放入列表框中,${ValSub}
工作正常,但我在var ${var_Master}
上收到错误:
** InvalidSelectorException:消息:无效的选择器:指定了无效或非法的选择器(会话信息:chrome = 64.0.3282.167) (司机信息:chromedriver = 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform = Windows NT 10.0.14393 x86_64)
使用以下代码示例:
${var_sub} Get File ../resources/var_sub.txt
@{list} Split To Lines ${var_sub}
${var_Master} Get File ../resources/var_master.txt
:FOR ${line} IN @{list}
\ ${ValSub}= Get Variable Value ${line}
\ sleep 1s
\ select from list by value name=merchant_id ${ValSub}
\ select from list by value name=master_marchant_id ${var_Master}
答案 0 :(得分:0)
我用这种方法来解决我的问题
${var_master} Get File ../resources/var_master.txt
@{list} Split To Lines ${var_master}
:FOR ${lineb} IN @{list}
\ ${ValMas}= Get Variable Value ${lineb}
${var_sub} Get File ../resources/var_sub.txt
@{list} Split To Lines ${var_sub}
:FOR ${line} IN @{list}
\ ${ValSub}= Get Variable Value ${line}
\ sleep 1s
\ select from list by value name=master_marchant_id ${ValMas}
\ select from list by value name=merchant_id ${ValSub}
答案 1 :(得分:0)
在Robot Framework中,无需创建自定义导入例程来创建变量,因为它有一个标准关键字:Import Variables
(Documentation)。
在下面的示例中,我使用的是YAML标记语言中的文件,该文件允许以人类可读的格式创建特定的Python和Robot variable types列表,词典和标量。也可以导入声明对象的python文件。
在这个例子中,我创建了一个模拟标量变量master
和一个模拟列表变量list
,以证明循环是可能的,并将Select From List By Value
模拟为自定义关键字。
<强> vars.yaml 强>
master: master value
list:
- item 1
- item 2
- item 3
<强> example.robot 强>
*** Test Cases ***
TC1
Import Variables ${EXECDIR}/vars.yaml
:FOR ${line} IN @{list}
\ sleep 1s
\ select from list by value name=master_marchant_id ${master}
\ select from list by value name=merchant_id ${line}
*** Keywords ***
Select From List By Value
[Arguments] ${locator} ${value}
Log Selecting "${value}" from "${locator}" element.