我在 python 中使用机器人框架来创建内部使用 selenium2library 关键字的关键字。
我在下面的代码片段中发现了一个问题,该代码片段出现在我的 python 关键字定义模块中。
状态=BuiltIn().run_keyword_and_continue_on_failure(sel.click_button('wlbasic_11n_value_01'))
这里,lbasic_11n_value_01是要点击的元素的id。
我希望即使此点击按钮失败也能执行我的关键字,因此我使用 run_keyword_and_continue_on_failure 关键字。
有趣的是,单击按钮后我看到一条错误消息,指出关键字名称应该是字符串。
何时 make sel.click_button('wlbasic_11n_value_01') -> 'sel.click_button('wlbasic_11n_value_01')'
python关键字代码->
def check():
sel = BuiltIn().get_library_instance('Selenium2Library')
title = sel.get_title()
BuiltIn().log_to_console('Making the Router Mode Change Now')
status = BuiltIn().run_keyword_and_continue_on_failure(sel.click_button('wlbasic_11n_value_01'))
根本没有检测到关键字,并且点击永远不会起作用。
我在这里缺少什么,我是机器人框架的新手。
任何调试帮助将不胜感激。
最佳答案
Interestingly, the click of the button happens but then i see an error message saying the keyword name should be a string.
该消息准确地告诉您问题是什么,为什么您忽略它告诉您的内容? run_keyword_and_continue_on_failure
需要关键字的字符串名称,并且您向其传递一个函数 (sel.click_button(...)
)。
没有必要使用run_keyword_and_continue_on_failure
——只需在代码周围放置一个try/except,这将完成同样的事情:
try:
sel.click_button('wlbasic_11n_value_01')
except Exception as e:
<handle or ignore the error however you wish here...>
如果您希望继续使用 run_keyword_and_continue_on_error
,请按照其说明操作并以字符串形式提供关键字:
status = BuiltIn().run_keyword_and_continue_on_failure(
'Click Button', 'wlbasic_11n_value_01')
)
关于python - ROBOT 框架在内置库关键字 'run_keyword_and_continue_on_failure' 中使用 selenium2library 关键字时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40101273/