为什么google-chrome-devtools通过XPath识别的元素数量少于通过CssSelector识别的元素数量 [英] Why does google-chrome-devtools identifies less number of elements through XPath then number of elements identified through CssSelector

查看:63
本文介绍了为什么google-chrome-devtools通过XPath识别的元素数量少于通过CssSelector识别的元素数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此.

使用以下

使用以下

那么,为什么 google-chrome-devtools 通过 XPath 标识的元素数量少于通过 CssSelector

标识的元素数量?>

解决方案

XPath正在按词法检查字符串 text show-more__control @class 属性值./p>

CSS表达式在语义上检查 @class 属性值,这些属性值指示 div 应该同时具有 text show-more__control 样式.

有10个满足CSS语义选择标准的 div 元素未能通过XPath词汇标准,因为它们的 @class 在词汇上是

 文本show-more__control可点击^^^^^^^^^^^ 

测试 @class 的通常解决方法是分别填充并检查每个类:

 //div [contains(concat('',@ class,''),'text')并包含(concat('',@ class,''),'show-more__control')] 

此XPath返回25个 div 元素,就像CSS选择器一样.

注意:这里特别棘手的是,静态源中没有 div/@ class 属性值的 clickable 部分在 div 对象的动态属性中.

I am trying to identify the elements containing the reviews on this .

Using the following :

//div[@class='text show-more__control']

The number of elements identified are: 15

Snapshot:

Using the following :

div.text.show-more__control

The number of elements identified are: 25

Snapshot:

So, why does google-chrome-devtools identifies less number of elements through XPath then number of elements identified through CssSelector

解决方案

The XPath is checking @class attribute values lexically for the string, text show-more__control.

The CSS expression is checking semantically for @class attribute values that indicate that the div should have both the text and the show-more__control styles.

There are 10 div elements that satisfy the CSS semantic selection criteria that fail the XPath lexical criteria because their @class lexically is

text show-more__control clickable
                       ^^^^^^^^^^

The usual workaround for testing @class is to pad and check each class separately:

//div[    contains(concat(' ',@class,' '), ' text ')
      and contains(concat(' ',@class,' '), ' show-more__control ') ]

This XPath returns 25 div elements, just like the CSS selector.

Note: Particularly tricky here is that clickable parts of the div/@class attribute value are not present in the static source, only in the dynamic properties on the div objects.

这篇关于为什么google-chrome-devtools通过XPath识别的元素数量少于通过CssSelector识别的元素数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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