Chrome Elements console does not show unique element when given xPath

谁都会走 提交于 2020-07-22 05:48:26

问题


if I press F12, go to Elements and click ctrl+F to search for a xPath, if I find only one element, that element is not highlighted (but Chrome will point out 1 of 1). If i find more than one elements, Chrome highlights from the second one. Problem occures also when I use indexes in xPath: (//a)[1].


回答1:


Seems like you are talking about this bug https://bugs.chromium.org/p/chromium/issues/detail?id=1106703 which was reported in the Chromium issue forums.

It was introduced in Chrome 84 with this change https://developers.google.com/web/updates/2020/05/devtools

I guess we can only wait or downgrade to Chrome 83 (which might not be possible in a corporate environment)




回答2:


It seems Chrome returns every element with an attribute containing part of an url (meta with @content, script with @src,...). That's why you got a script element when //a is your input. However, (//a)[1] should work and should return the first anchor (tested fine with Edge Chromium and Chrome).

Try to use this workaround to select the element :

//a[self::a]

To get the first anchor on the page, use :

(//a[self::a])[1]

Images for reference :



来源:https://stackoverflow.com/questions/62950893/chrome-elements-console-does-not-show-unique-element-when-given-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!