【问题标题】:Robotframework: How to use Tabindex as locator?Robotframework:如何使用 Tabindex 作为定位器?
【发布时间】:2026-02-10 15:20:04
【问题描述】:

我希望这里的社区可以帮助我。我被一个测试用例困住了,一个相当简单的输入。 问题是在网页上,我有两个需要填充的输入字段。两者的 CSS 相似。唯一的例外是选项卡索引值。

<input type="text" class=“text-dropdown-input-field " ag-class="getInputClass()" ag-keydown="inputKey($event, true, true, false, true)" tabindex="100">


<input type="text" class=“text-dropdown-input-field" ag-class="getInputClass()" ag-keydown="inputKey($event, true, true, false, true)" tabindex="120">

我在机器人文件中使用它。

input text                  tabindex:100  ${val1}
input text                  tabindex:120  ${val2}

我失败了:

消息:找不到定位器“tabindex:100”的元素。

还有其他选择吗?

谢谢。

【问题讨论】:

  • 既然tabindex是一个属性,你试过//input[@tabindex='100']吗?
  • 谢谢。这似乎可以解决问题!再次非常感谢。

标签: selenium robotframework


【解决方案1】:

您无法按照您的方式查询 tabindex。 tabindex 是一个属性,所以一个简单的 xpath 应该是这样的:

//input[@tabindex='100']

【讨论】: