在表格行中搜索文本

时间:2022-03-09 07:38:45

I'm trying to search within a single table row for my cucumber test.

我试图在一个表格行中搜索我的黄瓜测试。

I have each row formatted like this:

我将每行格式化如下:

%tr
  %td= title
  %td= complete
  %td= goal

And I am looking to search within a row with a given title, and check the goal

我希望在一行中搜索给定的标题,并检查目标

Is there a simple way to accomplish this?

有没有一种简单的方法可以做到这一点?

2 个解决方案

#1


49  

For anyone else who stumbles on this question, I think a better way to do this is:

对于任何在这个问题上犯错误的人,我认为更好的方法是:

find('tr', text: 'My title').should have_content(goal)

This way you're not adding a title attribute when it's not really needed

这样您就不会在不需要的时候添加标题属性。

#2


2  

I would probably add an attribute to the td you're interested in. Do something like:

我可能会向您感兴趣的td添加一个属性。做些什么:

%tr
  %td{title= "#{title}"}= title
  %td= complete
  %td= goal

Then you can refer to this question on * about finding within a specific element using css.

然后您可以参考*上关于使用css在特定元素中查找的问题。

Capybara, finding within a css element

在css元素中找到的水豚

#1


49  

For anyone else who stumbles on this question, I think a better way to do this is:

对于任何在这个问题上犯错误的人,我认为更好的方法是:

find('tr', text: 'My title').should have_content(goal)

This way you're not adding a title attribute when it's not really needed

这样您就不会在不需要的时候添加标题属性。

#2


2  

I would probably add an attribute to the td you're interested in. Do something like:

我可能会向您感兴趣的td添加一个属性。做些什么:

%tr
  %td{title= "#{title}"}= title
  %td= complete
  %td= goal

Then you can refer to this question on * about finding within a specific element using css.

然后您可以参考*上关于使用css在特定元素中查找的问题。

Capybara, finding within a css element

在css元素中找到的水豚