Selenium Automation - 需要 xpath 来定位 2 UI 个具有几乎相同属性的元素,这些元素位于不同的 HTML 标记中
Selenium Automation - Need xpath to locate 2 UI elements with almost same properties located in different HTML tags
这里的场景是我需要断言作业名称的状态是否更改为已完成,但问题是在 UI 页面上作业状态 HTML 元素*(标题= "Completed")* 对于所有不同的作业名称都是相似的*(title="Job1")*。
下面是示例 HTML 代码:
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job1">Job1</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job2">Job2</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job3">Job3</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
我想要一个能够唯一地指向已完成状态的职位的定位器,即:我想要一个 xpath,它将是以下 2 个 xpath 结果的组合输出:
//span[@title='job1'] and //button[@title='Completed']
注意:这是针对
收到的答复的跟进问题
要唯一标识每个 button
,您可以找到 following::span[1]
,然后找到按钮。
//span[@title='Job1']/following::span[1]/button[@title='Completed']
//span[@title='Job2']/following::span[1]/button[@title='Completed']
//span[@title='Job3']/following::span[1]/button[@title='Completed']
这里的场景是我需要断言作业名称的状态是否更改为已完成,但问题是在 UI 页面上作业状态 HTML 元素*(标题= "Completed")* 对于所有不同的作业名称都是相似的*(title="Job1")*。
下面是示例 HTML 代码:
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job1">Job1</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job2">Job2</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
<div class="flex-primary"><i title="Completed" class="fa fa-cube provider-logo hwx-secondary orange"></i><span class="hwx-title" title="Job3">Job3</span> </div>
<span><button class="btn btn-icon btn-transparent inline-overview-actions" eventkey="1" title="Completed"><i class="fa fa-play-circle hwx-secondary inline-actions-overview no-select"></i></button></span>
我想要一个能够唯一地指向已完成状态的职位的定位器,即:我想要一个 xpath,它将是以下 2 个 xpath 结果的组合输出:
//span[@title='job1'] and //button[@title='Completed']
注意:这是针对
要唯一标识每个 button
,您可以找到 following::span[1]
,然后找到按钮。
//span[@title='Job1']/following::span[1]/button[@title='Completed']
//span[@title='Job2']/following::span[1]/button[@title='Completed']
//span[@title='Job3']/following::span[1]/button[@title='Completed']