如何使用 page.find 通过 rspec 测试查找变量 [英] How to find a variable with rspec tests using page.find

查看:35
本文介绍了如何使用 page.find 通过 rspec 测试查找变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试用例,我的大多数其他页面都至少有一个字段是纯文本,可以使用以下方法找到:

I have a test case, most of my other pages have at least one field that is just straight text and can be found using:

page.find("tr", text: "What I filled in").find("a.tick").click

这个页面所有的选项都是下拉选择的,那么我如何找到一个变量呢?其余的语法如下所示:

This page all of the options are drop down selects, so how do I find a variable? The rest of the syntax looks like this:

it "edits person job and redirects to index" do
    expect(p = FactoryGirl.create(:person)).to be_valid()
    expect(j = FactoryGirl.create(:job)).to be_valid()
    visit new_job_path
    select p.name, from: "person_job_person_id"
    select p.name, from: "person_job_job_id"
    click_button "create person job"
    page.find("tr", p).find("a.tick").click
end

找不到要点击的p?

推荐答案

如果你想点击 p 元素,你可以使用 css 选择器xpath:

If you want to click on the p element, you can easily do it with css selector or xpath:

find(:css, 'the css selector of your p element').click


find(:xpath, 'the xpath of your p element').click

例如

find(:css, 'body > div.layout > div > button').click

如果您使用的是 Chrome,您可以通过检查您的元素、右键单击其代码并复制 css 选择器xpath<来轻松找到它们/strong>.

If you are using Chrome, you can easily find them by inspecting your element, right click on his code and copying the css selector or the xpath.

这篇关于如何使用 page.find 通过 rspec 测试查找变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆