Capybara, checking HTML element by ID and Class

后端 未结 1 1371
感情败类
感情败类 2021-02-07 05:56

Two questions from a beginner.

Q1- Is it possible to assert the existence of an HTML node by ID and class? For example, to see if the following element exists:



        
1条回答
  •  难免孤独
    2021-02-07 06:26

    You can combine the selectors.

    For your first question, the following checks for a div with id "first" and class "drawer":

    page.should have_css('div#first.drawer')
    

    For your second question, the within block can use the same css-selector as above:

    within('div#first.drawer') do
    

    Or if you really prefer xpath, you can do:

    within("//div[@id='first' and @class='drawer']") do
    

    A good reference for css-selectors: http://www.w3.org/TR/CSS2/selector.html

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