Capybara, finding within a css element

前端 未结 4 1323
时光说笑
时光说笑 2021-02-07 07:31

I\'m working with Ruby on Rails 3, Cucumber, and Capybara

I\'ve been searching for quite some time, and I can\'t figure out how to find a specific page element within a

相关标签:
4条回答
  • 2021-02-07 07:53

    I guess all answers should work but now Capybara doesn't use should anymore it uses expect

    expect(page).to have_css("#table", :text => "[Name]")
    expect(page).to have_css('h2', :text => 'stuff')
    
    0 讨论(0)
  • 2021-02-07 08:00

    To find a specific element:

    page.find('#table').should have_text('stuff')
    
    0 讨论(0)
  • 2021-02-07 08:01

    Capybara's within matcher only matches the first result, so if you have multiple h2 tags, it'll only look in the first one.

    Instead, try have_css with the :text option.

    page.should have_css("#table", :text => "[Name]")
    page.should have_css('h2', :text => 'stuff')
    
    0 讨论(0)
  • 2021-02-07 08:01

    I've done stuff like this: page.all(:css, 'button.btn-primary.days.active').size.should == 1

    To check if there are any elements that contain a specific set of classes.
    I didn't need to look for a particular text value of the element though. I just wanted to ensure the existence of the element, and how many of them there were.

    0 讨论(0)
提交回复
热议问题