1

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]. enter image description here

enter image description here

enter image description here

CCC
  • 170
  • 1
  • 15

3 Answers3

2

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)

Oikuar
  • 55
  • 4
1

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 :

A B C

E.Wiest
  • 5,425
  • 2
  • 7
  • 12
  • It did not work. It's doing the same thing, it finds the element but it does not highlight it – CCC Jul 17 '20 at 11:02
  • Checking better, it does not show some other //a elements, don't know why, it seems random. – CCC Jul 17 '20 at 11:08
  • OK. As suggested by @Oikuar, downgrade your Chrome version or use the built-in JS console (`$x('//a')`) or `ChroPath` addon to test your XPath expressions. – E.Wiest Jul 17 '20 at 15:37
0

The root cause is DevTools within Google Chrome 84.0 doesn't highlights the first matching element.

If, the locator finds a single match, the search result does show 1 of 1 but the WebElement isn't getting highlighted within the HTML DOM

As a demonstration, the Search Box within the Google Home Page can be identified uniquely using the :

[name='q']

or using the :

//*[@name='q']

within Google Chrome 84.0, does finds the element and shows 1 of 1 but the element is not getting highlighted.

devtools_issue

Incase, there are multiple element matching to the Locator Strategy, barring the first matched element, the other elements does gets highlighted.


Bug in Chrome 84

This issue was raised within Platform>DevTools queue through Issue 1108311: The first matched element in the Elements panel is not getting highlighted as per the cssSelector and had been merged into Issue 1103316: Elements search does not resolveNode (highlight text, etc) on first search result where we are actively tracking the issue.


Solution

As per @bugdroid the main issue was caused because a check to ensure the search results were valid did not account for the case where the index was 0, so all highlight results of index 0 (index 1 to the user) were no longer highlighted.

The fix for this issue is Merge-Approved in:


Alternate Solution

For alternate solutions using the current Version 84.0.4147.89 you can find a detailed discussion in Why XPath does not highlighted the yellow mark in Chrome84?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352