The following works great:
find "img[src='https://www.example.com/image']"
But I want to also find
find "img[src='https://www.example.com/image?foo=bar']"
How to use a regex within the attribute in the finder?
You can check that an attribute starts with a certain value using ^=
:
find("img[src^='https://www.example.com/image']")
The article, The Skinny on CSS Attribute Selectors , describes the various checks (equals, starts with, ends with, etc.):
#Equals
find("img[src='https://www.example.com/image']")
#Contains somewhere
find("img[src*='https://www.example.com/image']")
#Begins with
find("img[src^='https://www.example.com/image']")
#Ends with
find("img[src$='https://www.example.com/image']")
您可以使用class
选项,如find("div", class: /some-class/)
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.