Search code examples
capybara

How do I specifiy specific element with Capybara?


I'm testing if the Google Maps api works and loads, so upon loading I would like to confirm specific elements inside the map to make sure it loaded.

My code so far:

# ... prob put a sleep 1 here maybe to account for possible delay in map load
expect(page).to have_css ('#map')

section = find('#map')
expect(section).to have_css('.gm-control-active')  

However, there are 3 .gm-control-active elements inside the Google Map:

1) aria-label="Zoom in" title="Zoom in"
2) aria-label="Zoom out" title="Zoom out"
3) aria-label="Toggle fullscreen view" title= "Toggle fullscreen view"

What's the syntax to specify one of these?


Solution

  • You can use any css, which includes being able to use attribute selectors. Therefore you could do something like

    expect(section).to have_css('.gm-control-active[title=“Zoom in”]') 
    

    Or whatever other attributes you want to match against