Thanks to the flexible system, every element in a document can be checked for existence. There are several ways to select an element, since not all selectors are equally easy to use.
- Text selectors are the easiest to use selectors. They are used to define text that must appear on a web page. The text must appear exactly as described. A text selector is suitable for all types of documents.
- CSS selectors or CSS paths are best suited for selecting elements that are in the visible area of HTML documents. In most cases, these are determined by certain classes or IDs.
- XPath selectors are among the more complex selectors, but they gain more flexibility. XPath selectors can be used to name individual elements or just attributes in great detail, which then need to be checked. In contrast to CSS selectors, XPath can also be used to address elements that are located, for example, in the <head> of an HTML document.
- Regular expressions are the supreme discipline among selectors. They can be used to search for anything you want. The high flexibility, however, is paid for by increased complexity. If you decide to use regular expressions, you should familiarize yourself with the website regex101.
Editorially maintained websites can be challenging if they are very advertising intensive. Advertising is often not neatly programmed and leads to syntactically incorrect HTML code. In this case, all checks that can be covered by HTML as a source should use this. The others where it is important to check the DOM should use it. This should not be many.
- exists - checks whether an element occurs at least once in the document.
- contains - checks if an element exists and if the content contains a certain text. Only the first element found is checked.
- equals - the selected element must correspond to the exact text. Only the first element found is checked.
- occurs at most - the specified selector must occur at least X times in the document.
- occurs at least - the selected selector must not occur more than X times in the document.