ruby-on-rails – 如何在Capybara finder中使用正则表达式?

栏目: Ruby · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/14635474/how-to-use-regex-in-a-capybara-finder

以下作品很棒:

find "img[src='https://www.example.com/image']"

但我也想找到

find "img[src='https://www.example.com/image?foo=bar']"

如何在finder中的属性中使用正则表达式?

您可以使用^ =检查属性是否以特定值开头:
find("img[src^='https://www.example.com/image']")

文章 The Skinny on CSS Attribute Selectors 描述了各种检查(等于,开始,结束等):

#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']")

翻译自:https://stackoverflow.com/questions/14635474/how-to-use-regex-in-a-capybara-finder


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Machine Learning

Machine Learning

Kevin Murphy / The MIT Press / 2012-9-18 / USD 90.00

Today's Web-enabled deluge of electronic data calls for automated methods of data analysis. Machine learning provides these, developing methods that can automatically detect patterns in data and then ......一起来看看 《Machine Learning》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码