Is it possible to have a regex in CSS Selector for a tag?

I want to find elements using selenium webdriver with tag h2

or h3

.

Is it possible to have a generic css selector for the above requirement?

Something similar to [tag^='h']

or [att^=str]

?

+3


source to share


3 answers


For attributes, yes you can. But for elements, you can separate the values ​​by commas. W3 CSS Selectors



Selector            Example              Description                                                                              CSS
element1,element2   h1,h2                Selects every <ul> element that are preceded by a <p> element                             3
[attribute~=value]  [title~=flower]       Selects all elements with a title attribute containing the word "flower"                 2
[attribute|=value]  [lang|=en]            Selects all elements with a lang attribute value starting with "en"                      2
[attribute^=value]  a[href^="https"]      Selects every <a> element whose href attribute value begins with "https"                 3
[attribute$=value]  a[href$=".pdf"]       Selects every <a> element whose href attribute value ends with ".pdf"                    3
[attribute*=value]  a[href*="w3schools"]  Selects every <a> element whose href attribute value contains the substring "w3schools"  3

      

+1


source


Use a comma-separated list of selectors. Use a selector for your case h2, h3

. See the W3C Recommendation for details .



+2


source


This is not a direct answer to the question, but as an additional option, you can also use XPath

that matches both elements by running "h"

letter:

//*[starts-with(name(), 'h')]

      

+1


source







All Articles