Selenium 自动化 - 需要组合 1 个或多个 xpath 定位器以形成单个定位器 [英] Selenium Automation - Need to combine 1 or more xpath locators to form a single locator

查看:37
本文介绍了Selenium 自动化 - 需要组合 1 个或多个 xpath 定位器以形成单个定位器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

以下是示例 HTML 代码:

<i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing "title=已完成"></i><span class="hwx-title";title=job1">job1

<div class="flex-primary"><i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing "title=已完成"></i><span class="hwx-title";title=job2">job2

<div class="flex-primary"><i class="gray hwx-test test-status fa provider-logo hwx-test na na-testing "title=已完成"></i><span class="hwx-title";title=job3">job3

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

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

解决方案

下面的 xpath 将为您提供包含 jobname 为 job1 和 title 为 completed

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

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

//span[@title='job1']/parent::div/i[@title='已完成']

The scenario here is I need to Assert whether the status of a jobname is changed to Completed, But the issue is that on the UI page the Job status HTML element is similar for all the different job names.

Below is the sample HTML code:

<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>

I want a locator which will uniquely be able to point to a job title in completed state i.e: I want a xpath or any other locator which can combine & give me 1 single output for below 2 xpath's result:

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

解决方案

The below xpath will give you the div which contains jobname as job1 and title as completed

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

Below xpath will point to the i tag of jobname of job1 which is completed

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

这篇关于Selenium 自动化 - 需要组合 1 个或多个 xpath 定位器以形成单个定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆