Are you writing & verifying XPath in DevTools?
Recently I learned about this concept that Browser DevTools is not the right platform to verify XPath & CSS selectors. I was shocked that for so many years whatever I was doing that was wrong. Reason, DevTools is not built just to verify XPath & CSS, it also gives the string search result when we verify with CMD+F. In DevTools console, it gives wrong results in many cases like shadow DOM, nested Shadow DOM, iframes and nested iframes etc.