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

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

内容简介:翻译自: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


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

查看所有标签

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

更快速网站

更快速网站

Steve Souders / 2009年12月 / 42.00元

对于任何成功的网站来说,性能是至关重要的。但伴随着不断增长的丰富内容和Ajax的过度使用,如今的Web应用已经将浏览器推至性能极限。在本书中,Google的Web性能专家和前任雅虎首席网站性能官Steve Souders提供了宝贵的技术,来帮助你优化网站性能。 作者的上一本书是非常畅销的《High Performance Web Sites》,它透露了80%的网页加载时间是花在客户端,使网络......一起来看看 《更快速网站》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试