作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
\ Run Keyword If ${i} == 7 log to console Testing Variant 1
\ ${is visible}= Run Keyword And Return Status Element Should Be Visible (//li[@class='_8HqL0'])[${i}]
\ Run Keyword If ${is visible} Run keywords
\ ... Scroll Element Into View (//li[@class='_8HqL0'])[${i}]
\ ... AND Click Element (//li[@class='_8HqL0'])[${i}]
\ ... AND sleep 2s
\ ... set variable ${Ad_Path} Get Text //*[@class='rui-3blDo _1Uh38 _27AdP']
\ ... AND log to console ${Ad_Path}
您好,我想在 FOR 中的 IF block 内使用 GET TEXT 事件,但它给出了一个错误,说明关键字名称不能为空帮助
最佳答案
您不能在 Run Keyword
/Run Keyword If
中构造 ${variable}= Returned Value From Keyword
,因为后者期望传递给它的所有内容都是一个关键字 - 并且它认为 ${variable}
也是一个。
有一个“解决方法”——Run Keyword If
传播回其关键字中最后返回的值,并且可以将其设置为变量。例如。你可以这样做:
${variable}= Run Keyword If ${condition} Returned Value From Keyword ELSE Set Variable other value
注意这个构造中的 ELSE
- 没有它,如果条件为假,变量将是未定义的 - 将留下一个值 None
(数据类型) .
自然地,如果 Run Keyword If
有多个步骤(比如您的控制台日志),您必须将其分解 - 一个“做事”的 block ,另一个(或其他) ) “赋值”。
我在引号中输入了“workaround”,因为它实际上不是这样的 - 这是关键字设计使用的方式。
关于robotframework - 在 Run 关键字 If 中分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60268697/
我是一名优秀的程序员,十分优秀!