【问题标题】:RobotFramework Locate elements with identical classRobotFramework 定位具有相同类的元素
【发布时间】: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


【解决方案1】:

元素需要在视口中,试试下面给出的代码:

Execute JavaScript    window.document.evaluate("//input[contains(@id,'pflege_beduerftig1')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView(true);

【讨论】:

  • 我试过了,但是错误代码和之前一样:'ElementNotInteractableException: Message: element not interable (Session info: chrome=90.0.4430.212)' 我也试过了:'Scroll Element进入视图,但它没有帮助。
  • 如何手动与该元素交互?你必须执行鼠标滚动吗?
  • 不,弹出窗口实际上不可滚动,所以我不知道为什么该元素不可点击。该元素是一个可点击的单选按钮。是否有可能是弹出窗口的问题?
  • 如果你可以手动点击那么弹出应该不是问题
  • 是的,我知道我也是这么想的,但问题仍然没有解决。
猜你喜欢
  • 2018-04-04
  • 2015-10-04
  • 2022-10-07
  • 1970-01-01
  • 2020-05-03
  • 2021-07-18
  • 1970-01-01
  • 2011-06-12
  • 2016-01-14
相关资源
最近更新 更多