在 Xpath 中使用 OR 条件来标识相同的元素 [英] Using an OR condition in Xpath to identify the same element

查看:23
本文介绍了在 Xpath 中使用 OR 条件来标识相同的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个逻辑,首先点击下一个按钮获取当前页面的标题,再次获取标题,如果两个标题相同,意味着导航没有移动到下一页,它会再次点击下一步.

I have this logic which gets the current page's title first clicks on next button, fetches the title again and if both the titles are the same, meaning navigation has not moved to the next page, it clicks on Next again.

但是,我的问题是 title 元素的 Xpath 不同——同一个 title 元素有两个 Xpath.一个是某些页面,另一个是其他一些页面.

However, my problem is that the title element's Xpath differs - the same title element has two Xpaths. One is some pages the other in some other pages.

要么是这个,

(.//span[@class='g-title'])[2]

.//span[@class='g-title']

那么,我该如何处理呢?

So, how can I handle this?

推荐答案

如果元素有两个xpath,那么你可以写两个xpath如下

If the element has two xpath, then you can write two xpaths like below

<代码>xpath1 |xpath2

例如://input[@name="username"] |//输入[@id="wm_login-username"]

它将选择任何一个 xpath

It will choose any one xpath

这篇关于在 Xpath 中使用 OR 条件来标识相同的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆