没有带名称的关键字'删除字符串'发现

时间:2017-11-13 05:20:37

标签: selenium robotframework

我试图从下面提到的字符串中获取数字70:

  

显示70个参赛作品中的1到50个

我尝试过以下代码:

${text} = Get Text xpath=//div[@id='DataTables_Table']
Page Should Contain Showing 1 to
${edited_text} = Remove String ${text} Showing 1 to 50 of

但是我得到了下面提到的错误:

  

没有带名称的关键字'删除字符串'找到。

即使我使用以下关键字,我也会收到相同的错误:

  

获取子串,替换字符串

1 个答案:

答案 0 :(得分:4)

When keywords aren't found, this typically means that the library has not been loaded. With the exception of the BuiltIn library, all others need to be declared. A full working example of your code is below:

*** Setting ***
Library    String

*** Test Cases ***
tc
    ${text}           Set Variable    Showing 1 to 50 of 70 entries
    ${edited_text}    Remove String     ${text}     Showing 1 to 50 of

    ${matches}        String.Get Regexp Matches    ${text}    [0-9]{1,2}
    Log               "Max is:" ${matches[2]}

As you're intention is to match the 3rd digit group, the regular expression match seems like the cleanest approach.