Google Chrome provides a built-in debugging tool called "Chrome DevTools" out of the box, which includes a handy feature that can evaluate or validate XPath/CSS selectors without any third party extensions.
This can be done by two approaches:
Elements
panel to evaluate XPath/CSS selectors and highlight matching nodes in the DOM.$x("some_xpath")
or $$("css-selectors")
in Console
panel, which will both evaluate and validate.F12
to open up Chrome DevTools.Elements
panel should be opened by default.Ctrl
+ F
to enable DOM searching in the panel.header
should match everything (inline CSS, scripts etc.) that contains the word header
, instead of match only elements.
F12
to open up Chrome DevTools.Console
panel.$x(".//header")
to evaluate and validate.$$("header")
to evaluate and validate.[ ]
is shown.$x(".//article") [<article class="unit-article layout-post">…</article>] $x(".//not-a-tag") [ ]
$x(".//header/") SyntaxError: Failed to execute ‘evaluate‘ on ‘Document‘: The string ‘.//header/‘ is not a valid XPath expression. $$("header[id=]") SyntaxError: Failed to execute ‘querySelectorAll‘ on ‘Document‘: ‘header[id=]‘ is not a valid selector.
console里面执行javascript代码,操作dom对象。
每个载入浏览器的 HTML 文档都会成为 Document 对象。Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问。
通过id获取
document.getElementById(“id”)
通过name获取
document.getElementsByName(“Name”) 返回的是list
通过标签名选取元素
document.getElementsByTagName(“tag”)
通过CLASS类选取元素
document.getElementsByClassName(“class”)
兼容性:IE8及其以下版本的浏览器未实现getElementsByClassName方法
通过CSS选择器选取元素
document.querySelectorAll(“css selector")
兼容性:IE8及其以下版本的浏览器只支持CSS2标准的选择器语法
转自:
https://yizeng.me/2014/03/23/evaluate-and-validate-xpath-css-selectors-in-chrome-developer-tools/
https://blog.csdn.net/jamieblue1/article/details/101075193
使用Chrome DevTools(console ande elements panel)进行xpath/css/js定位
原文:https://www.cnblogs.com/puresoul/p/15194108.html