【问题标题】:Robot framework - How to go through X element while there are pages until element Y is found机器人框架 - 如何在有页面时通过 X 元素直到找到元素 Y
【发布时间】:2022-01-22 23:20:38
【问题描述】:

我最近刚接触 Robot 框架,似乎无法在任何地方找到我的确切问题的答案。

上下文:我需要浏览页面上的所有标题,直到找到由全局变量确定的特定标题。 UI 没有唯一的 ID,因此当我输入标题定位器时,我会得到 20 个或更多与此 XPath 匹配的元素。

还有分页,意思是我要找的标题可能在另一页。

我的全局变量,即我正在寻找的标题,是${audience_name_value},我在另一个关键字中得到了它的值。我认为这一点很有效,因为当这个标题在同一页上时,测试通过关键字

Page Should Contain Element ${current_page['audience_name_card_holder_title']}${audience_name_value}")].

问题是当我要查找的标题放在第二页或第三页等时。

我想迭代每个标题,直到找到正确的标题或单击下一个箭头继续搜索。


起初,我得到了错误:TypeError: Expected argument 1 to be a list or list-like, got string instead.

the created audience is in the inactive custom audience section
   ${elements}=  Get WebElements                  xpath://*[@id="pageContainer"]//div[contains(@class,"audienceCard__header__name")]/a
    FOR    ${element}    IN    @{elements}
        ${text}=    Get Text    ${element}
        Exit For Loop If        ${text} == ${audience_name_value}
    END

所以我尝试在下面创建一个列表,但现在我不断收到此错误: Evaluating expression 'RBT 2021-12-21 == RBT 2021-12-21' failed: SyntaxError: invalid syntax (<string>, line 1)

the created audience is in the inactive custom audience section
    ${elements}=  Get WebElements                  xpath://*[@id="pageContainer"]//div[contains(@class,"audienceCard__header__name")]/a
    ${list}=    Create List    ${elements}
    FOR    ${element}    IN    @{list}
        ${text}=    Get Text    ${element}
        Exit For Loop If        ${text} == ${audience_name_value}
    END
    

我没有想法,似乎找到了标题,但有一个语法错误我似乎无法修复。

恳请帮助 :D,谢谢!

【问题讨论】:

    标签: robotframework ui-automation browser-automation webautomation


    【解决方案1】:

    在这段代码中,您创建了一个列表,但它仍然从 Web 元素返回字符串。最好使用以下内容: 首先,在 ${var} 中捕获完整的网页内容,然后使用 kw 从 ${var} 中获取包含字符串或获取子字符串的行,将其与 kw Run 关键字 If/IF 循环一起使用。

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 2018-12-04
      • 2019-05-02
      • 2018-08-16
      • 2022-10-25
      • 2021-11-22
      • 2019-02-18
      • 1970-01-01
      • 2020-03-19
      相关资源
      最近更新 更多