Check if Selector Is Correct and Unique
Here is how you can check whether a selector is correct and unique before you run your TaskBot.
Open Chrome DevTools by right-clicking any spot on the webpage and selecting Inspect.

Now enter the following command in the Console tab:
document.querySelectorAll("PASTE YOUR SELECTOR HERE")
In the example of Wikipedia's search button, it can be, for example, this selector (but you can use any other from the list you saw in the previous chapter One Element Can Have Many Selector Expressions):
document.querySelectorAll("button[class*='button'][type='submit']")
This is what it looks like in action:

Once you hit Enter, you will see that there is an element shown:

Once you expand the shown element and hover over it, you will see the button highlighted on the left side that is identified by that selector.

If your selector is not unique enough, the result will contain multiple elements. This means you need to make the selector more specific. Exception: Unless you are building a selector for a list (such as list of profiles, list of pages, etc.) — in this case keep reading this guide (lists will be explained in the sectionLists: Incremental CSS Selectors).
If the result does not show anything, your selector does not match any element or contains a typo. You need to try again, adjust it or build another one.
When you build your own selectors, always first check them with document.querySelectorAll directly on the website. This way you can avoid running your TaskBot every time you want to check validity of your custom built selector. It can save you some time.
Video Tutorial: Use document.querySelectorAll to Check Selector's Correctness and Uniqueness
Last updated