python - ROBOT 框架在内置库关键字 'run_keyword_and_continue_on_failure' 中使用 selenium2library 关键字时出现问题

标签 python keyword robotframework selenium2library

我在 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/

相关文章:

python - 网格搜索中带有第三个参数的自定义记分器

python - 处理多个应用程序覆盖 Django 中的管理命令

Mysql 多关键字相似搜索 - 按字符串中最多关键字排序

php - SEOstats API SEMrush关键词查询方法?

java - volatile 关键字有什么用?

robotframework - 如何修复 Robot Framework 中的 "Escaping empty cells with '\' before line continuation marker ' .. .' is deprecated"错误?

Python mod json + urllib2

linux - 是否可以使用机器人框架从另一台远程服务器连接到远程服务器

robotframework - Robot 框架中的多行注释

python - 检查 python 脚本是否正在 aws 实例上运行