【问题标题】:Select parent div and not the child div in Robot Framework在 Robot Framework 中选择父 div 而不是子 div
【发布时间】:2022-01-22 02:05:18
【问题描述】:

我是新手,我正在 Robot Framework 中开发测试自动化,它需要选择父 div,但子 div 是始终点击的那个。

这是我的射频代码:

Wait and click element          xpath: //div[contains(@class,'parent') and .='orange']

这是 HTML

<div class="parent">
   <div class="child"></div>
   orange
</div>

我希望 TA 不要点击 div.child。有没有办法做到这一点?

div.class 宽度为 400px,div.child 宽度为 355px。每次我尝试点击 xpath: //div[contains(@class,'parent') and .='orange'],它总是点击 div.child

【问题讨论】:

  • 你想点击orange吗?
  • 是的,但是div.child的命中区域很大,占据了orange这个词的一半。

标签: html selenium xpath css-selectors robotframework


【解决方案1】:

您可以使用 xpath 轴 - 轴表示与上下文(当前)节点的关系,用于定位相对于树上该节点的节点。

Wait and click element    xpath://div[contains(text(),'orange')]//parent::div

【讨论】:

    【解决方案2】:

    使用Execute Javascript

    Execute Javascript  $('.parent').click()
    

    根据您的要求更新您的定位器。

    【讨论】:

    • 同样的事情发生
    • 你能更新错误日志,连同执行javascript的试验。
    【解决方案3】:

    试试

    Wait and click element          xpath://*[contains(text(),'orange')]
    

    【讨论】:

    • 同样的事情发生
    猜你喜欢
    • 1970-01-01
    • 2022-11-14
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多