【问题标题】:Handling with random button with Robot Framework使用 Robot Framework 处理随机按钮
【发布时间】:2021-04-24 05:21:09
【问题描述】:

我正在尝试使用带有 SeleniumLibrary 的 Robot Framework 来单击随机按钮生成器,HTML 是:

<div class="btn-number-password noselect">
<p class="btn btn-secondary btn-userpassword" data-keyboard="0">6 or 7</p>
<p class="btn btn-secondary btn-userpassword" data-keyboard="1">2 or 0</p>
<p class="btn btn-secondary btn-userpassword" data-keyboard="2">3 or 8</p>
<p class="btn btn-secondary btn-userpassword" data-keyboard="3">9 or 4</p>
<p class="btn btn-secondary btn-userpassword" data-keyboard="4">5 or 1</p></div>

它将生成按钮到如下字段:

[6 or 7] [2 or 0] [3 or 8] [9 or 4] [5 or 1]

这些数字每次都会随机播放,所以我尝试使用文本点击,但我尝试过的没有任何效果。

有没有办法使用这些按钮中的文本来点击机器人?

【问题讨论】:

  • 您可以在 xpath 表达式中使用逻辑 and 和 or 来匹配文本列表。
  • 使用 //*[contains(text(),'6')]

标签: selenium robotframework


【解决方案1】:

Chandrashekhar 刚刚问了我的问题,它成功了!再次感谢!

为了清楚起见,答案是:

Click Element                      //*[contains(text(),'1')][1]
Click Element                      //*[contains(text(),'4')][1]
Click Element                      //*[contains(text(),'7')][1]
Click Element                      //*[contains(text(),'2')][1]
Click Element                      //*[contains(text(),'5')][1]
Click Element                      //*[contains(text(),'8')][1]

你也可以使用一个类来改进你的元素搜索:

Click Element                      //*[@class='new_window'][1]//*[contains(text(),'1')][1]

【讨论】:

    猜你喜欢
    • 2014-04-26
    • 2014-06-25
    • 2017-08-08
    • 2017-04-30
    • 2015-12-09
    • 2015-11-26
    • 1970-01-01
    • 2019-02-25
    • 2018-11-30
    相关资源
    最近更新 更多