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

查看:107
本文介绍了在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]

OR

.//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"] | //input[@id="wm_login-username"]

它将选择任何一个xpath

It will choose any one xpath

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

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