How to use Regex or complex selector filters with Element click

I am currently using the :contains pseudo element with Element click to navigate a site I am scraping. I only want to navigate to pages accessed by items that end with the term "appliance". This works:

div#react-select-2--list div.Select-option:contains("appliance")

I want to be more selective, based on what the text starts with as well as what it ends with.

A regex that would match the items I am looking to select is:

\b[A-Z]{2}-[0-9]{3}.+?appliance\b

However, I don't know if I can use a regex with Element click. Is this possible?

If not, is there another way to select elements based on the start and end of string? Or a way to select something that contains("MX-0") AND contains("appliance")?

You can just stack contains, which works like "And", e.g.

div.Select-option:contains("MX-0"):contains("appliance")

Another method is to use not, e.g.

div.Select-option:not(":contains('Unwanted_text')")

This too is stackable and can be used with contains.

1 Like

I didn't even think about doing that. Thank you SO much!!