我正在测试 Google 地图 api 是否工作并加载,因此在加载时我想确认地图内的特定元素以确保其加载。
到目前为止我的代码:
# ... 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')
但是,Google 地图中有 3 个 .gm-control-active 元素:
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"
指定其中之一的语法是什么?
您可以使用任何 css,其中包括能够使用属性选择器。因此你可以做类似的事情
expect(section).to have_css('.gm-control-active[title=“Zoom in”]')
或者您想要匹配的任何其他属性