I'm new to all this, so this is very basic, but I think I've found an example where querySelector
is clearly more useful than XPath.
Let's say I want to get the URL of an account name under a YouTube video.
The relative XPath is:
//ytd-video-owner-renderer[@class='style-scope ytd-watch-metadata']//a[@class='yt-simple-endpoint style-scope yt-formatted-string'][normalize-space()='Guardian News']
It contains the username, so it won't work for every youtube video, whereas the JS Path is:
document.querySelector("ytd-video-owner-renderer[class='style-scope ytd-watch-metadata'] a[class='yt-simple-endpoint style-scope yt-formatted-string']")
This is more generic, so I should be able to use this to get the URL of that item.
I don't know how to do that, but am I right in seeing that as a benefit of using JS Path over XPath?