XPath//* vs//元素vs// [英] XPath //* vs //element vs //

查看:81
本文介绍了XPath//* vs//元素vs//的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找XPath时感到困惑:何时将//*放在开始位置以及何时仅将//放置将起作用.

I have a confusion in finding XPath: When to put //* at start and when to put just // will work.

例如,我正尝试在 https://www.myntra.com/上清除此内容 .网站首页上有一个带有HTML代码的搜索框

For example, I was trying to clear this thing on https://www.myntra.com/. There is one search box thereon the website home page with HTML code

<input placeholder="Search" class="desktop-searchBar" value="" data-reactid="529">

下面的XPath适用于上面的代码

the below XPath works for this above code

//*[@class='desktop-searchBar']

我仍然感到困惑,为什么在双斜杠(//)之后需要*.

I am still confused why I need a * after double slash(//).

推荐答案

  1. //*[@class='desktop-searchBar']

表示选择所有元素,而不考虑名称,其class属性值为desktop-searchBar.

says to select all elements, regardless of name, with an class attribute value of desktop-searchBar.

//input[@class='desktop-searchBar']

表示与#1相同,只是将元素命名为input.

says the same as #1 except constrains the element to be named input.

//[@class='desktop-searchBar']

在XPath中在语法上无效,因为它缺少必需的节点测试,例如input(名为input的元素)或*(任何元素).

is syntactically invalid in XPath because it's missing a required node test such as input (element named input) or * (any element).

这篇关于XPath//* vs//元素vs//的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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