【发布时间】:2021-08-15 12:29:08
【问题描述】:
我目前正在使用机器人框架和 seleniumlibrary 进行测试自动化。 我遇到了以下问题: 我找不到正确的元素,因为有两个具有相同类的元素。 这些元素位于我们系统的弹出窗口中。 两个元素的html是这样的:
第一个元素:
<mais-radio _ngcontent-jgg-c45="" _nghost-jgg-c46="" class="ng-untouched ng-pristine ng-valid">
<input _ngcontent-jgg-c46="" class="original-radiobutton ng-untouched ng-pristine ng-valid" type="radio" name="pflege_beduerftig" id="pflege_beduerftig0">
<div _ngcontent-jgg-c46="" class="mais-rb" tabindex="1">
</div></mais-radio>
第二个元素:
<mais-radio _ngcontent-jgg-c45="" _nghost-jgg-c46="" class="ng-untouched ng-pristine ng-valid">
<input _ngcontent-jgg-c46="" class="original-radiobutton ng-untouched ng-pristine ng-valid" type="radio" name="pflege_beduerftig" id="pflege_beduerftig1">
<div _ngcontent-jgg-c46="" class="mais-rb" tabindex="1"></div>
</mais-radio>
只有不同的 id 可以分隔这些元素,但 robotsframework 无法点击定位器找到 id 的元素。
除了使用 xpath 方法之外,我还有什么方法可以只找到第二个元素?
提前致谢!
【问题讨论】:
-
为什么不
ID = pflege_beduerftig1?使用此 ID 时遇到什么错误? -
如果我使用 ID = pflege_beduerftig1 我得到错误:ElementNotInteractableException:消息:元素不可交互(会话信息:chrome=90.0.4430.212)
-
这两个元素在树的某处应该有不同的父元素;因此,从您要定位的元素的唯一父级开始构建您的 css 定位器。
-
我已经试过了,但也没有用。
标签: html selenium selenium-chromedriver robotframework