hide-if-matches-computed-xpath
The hide-if-matches-computed-xpath
hides specific element whose class name or ID changes in runtime through a dynamically-built XPath query.
This snippet takes as a first parameter an XPath selector that's incomplete, due to a placeholder in the form {{}}
. The next parameters, searchQuery
and searchRegex
, tell the snippet how to fill the placeholder.
You can use hide-if-matches-computed-xpath
to:
Hide elements whose classes or IDs are randomized when a page refreshes
Hide elements that write flexible queries to take stylesheets, inline scripts, and regex into account
Hide elements that change at runtime
Always use double quotes instead of single quotes inside selectors. Though both are valid, eyeo uses single-quotes to enclose the selector as part of the filter syntax.
Parameters
Name | Description | Mandatory |
---|---|---|
query | The template XPath query that targets the element to hide. Use | Yes |
searchQuery | The XPath query that searches for an element to be used alongside searchRegex. | Yes |
searchRegex | The regular expression used to extract text from the innerHTML of the element that matches searchQuery. The extracted text gets injected into the query. | Yes |
waitUntil | An optional parameter that can be used to delay the running of the snippet until the given state is reached. Accepts | No |
Filter examples
The following table lists examples that use the hide-if-contains-and-matches-style
snippet:
Filter | Result |
---|---|
| Hides all elements with a class whose name matches any string in the div with an |
| Hides all elements that contain the text |
| Hides all elements that:
This filter runs when the document state is interactive. |
Debugging
The following table contains messages you'll find useful during debugging:
Message | When the error occurs | Definition |
---|---|---|
| Right after the snippet fires | Mandatory parameters are missing; double check your filter. |
| When the snippet begins to look for the | A node is searched for to find the string that matches the regular expression. |
| When a node matches the | A node element was found that will be used to find the string that matches the regular expression. |
| After | A node search was matched by the |
| After comparing the text inside the | A string was found that matches the regular expression. This string will be used to fill the XPath query. |
| After the placeholder in the XPath query has been replaced with the | The snippet has filled the placeholder and is looking for HTML elements that match the computed XPath query. |
| Right after an HTML element has been matched and hidden | The snippet has successfully matched and hidden a HTML element. |
Other resources
Last updated