0

Is there a way to find all div's on a page via their css class using a regexp if the classes match the regex? Below is an example snippet:

<div class="runtime">...</div>
<div class="runtime2">...</div>
<div class="runtime3">...</div>

I was hoping there is a way to get all divs via a regex because there could be more div's I want to find following that class format on the page but they change on a page by page basis.

1 Answer 1

1

For that format you can use a starts-with, and contains attribute selector

all('div[class^="runtime"], div[class*=" runtime"]', minimum:1)

The second selector is for the case where there's another class preceeding runtime... in the element. For a more general case there is no built in way to use a regex for class matching, although you could get an array of all the divs and then filter that based on the class attribute yourself (not going to be very performant)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! If we were in prison together, I'd protect you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.