Selenium Automation - 需要组合 1 个或多个 xpath 定位器以形成单个定位器

Selenium Automation - Need to combine 1 or more xpath locators to form a single locator

这里的场景是我需要断言作业名称的状态是否更改为已完成,但问题是在 UI 页面上,作业状态 HTML 元素对所有元素都是相似的不同的工作名称。

下面是示例 HTML 代码:

<div class="flex-primary">
<i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing " title="Completed"></i>
<span class="hwx-title" title="job1">job1</span>
</div>
<div class="flex-primary">
<i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing " title="Completed"></i>
<span class="hwx-title" title="job2">job2</span>
</div>
<div class="flex-primary">
<i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing " title="Completed"></i>
<span class="hwx-title" title="job3">job3</span>
</div>

我想要一个能够唯一指向已完成状态的职位的定位器 即:我想要一个 xpath 或任何其他定位器,它可以组合并给我 1 个低于 2 个 xpath 结果的单一输出:

//span[@title='job1'] and //i[@title='Completed']

下面的 xpath 将为您提供 div,其中包含工作名称 job1 和标题 completed

//span[@title='job1']/preceding-sibling::i[@title='Completed']/parent::div

下面的xpath会指向job1的jobname的i标签,即completed

//span[@title='job1']/parent::div/i[@title='Completed']