How to find a variable with rspec tests using page.find

蓝咒 提交于 2020-03-15 11:50:29

问题


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

it is unable to find the p to click?


回答1:


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

or

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

For example

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

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.



来源:https://stackoverflow.com/questions/34202552/how-to-find-a-variable-with-rspec-tests-using-page-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!