I'm trying to run rspec tests for clicking data for a part of the website which requires a number of table elements to be clicked. These elements represent a time element ( an hour each ) but don't have any ids. Here is the row:
我尝试运行rspec测试来为网站的一部分点击数据,这需要点击一些表格元素。这些元素代表一个时间元素(每个小时一个小时),但是没有任何id。这是行:
<tr class="ranges" data-time="5AM"></tr>
Here is the html equivalent of what I need to click:
这就是我需要点击的html代码:
<td data-date="04/14/15" data-time="5AM" data-disable="undefined"
class="selectable fadein-repeat"></td>
Here is what I tried so far:
以下是我迄今为止所尝试的:
find('.selectable fadein-repeat', text: "5AM").click
find(:xpath, "//tr[contains(.,'5AM')]/td/a", :date => '04/13/15').click
I've also tried many variations of the above code but couldn't get any of them to work.
我也尝试过上面代码的许多变体,但都无法让它们工作。
1 个解决方案
#1
0
To use data attributes, you need to add it to your selector. Try something along the lines of:
要使用数据属性,您需要将其添加到选择器中。尝试一些类似的事情:
find("td[data-time='5AM']").click
also - you can always check if it exists before trying to click on it (then change it back when you're sure it works). eg
同样,你可以在尝试点击它之前检查它是否存在(然后当你确定它有效的时候再把它改回来)。如
expect(page).to have_selector("td[data-time='5AM']")
#1
0
To use data attributes, you need to add it to your selector. Try something along the lines of:
要使用数据属性,您需要将其添加到选择器中。尝试一些类似的事情:
find("td[data-time='5AM']").click
also - you can always check if it exists before trying to click on it (then change it back when you're sure it works). eg
同样,你可以在尝试点击它之前检查它是否存在(然后当你确定它有效的时候再把它改回来)。如
expect(page).to have_selector("td[data-time='5AM']")