Home > Blockchain >  Capybara checking HTML class and ID
Capybara checking HTML class and ID

Time:03-23

I'm currently trying to find this element and have capybara validate that it's there. There's an element that shows up and I'm using page.should have_css to see if this element is there.

<i  ui-grid-one-bind-aria-label="aria.removeFilter" aria-label="Remove Filter">&nbsp;</i>

I'm currently trying to get to the ui-grid-icon-cancel and validate that it's there. Here is the code I'm using to validate it.

page.should have_css('class#ui-grid-icon-cancel')

What else can I do to fix this.

I'm expecting to validate the CSS element using capybara.

CodePudding user response:

You can use either of the following locator strategies:

  • css_selector using value of class attribute:

    page.should have_css('i.ui-grid-icon-cancel')
                           ^ here dot denotes classname
    
  • css_selector using value of aria-label attribute:

    page.should have_css('i[aria-label="Remove Filter"]')
    

CodePudding user response:

Did you try page.should have_css('.ui-grid-icon-cancel') . When looking for a class element, you need to use the notation of a period rather then explicitly putting the word "class". `

  • Related