hem*_*nik 5 css-selectors selenium-webdriver
我想使用带有h2
orh3
标签的 selenium webdriver 来查找元素。
是否可以有一个通用的 css 选择器来满足上述要求?
类似于[tag^='h']
或 的东西[att^=str]
?
对于属性,是的,可以。但对于元素,您可以用逗号分隔可能的值。W3 CSS 选择器
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
Run Code Online (Sandbox Code Playgroud)