Click overlay marker in Google Maps with capybara-webkit

后端 未结 2 1644
梦毁少年i
梦毁少年i 2021-02-18 14:11

Is there a way to click a Google Maps overlay with capybara-webkit? What about Capybara using Selenium? I want to test the content of the info window once the marker is selected

相关标签:
2条回答
  • 2021-02-18 14:16

    To test that there are n markers on the page:

    expect(find('.gmap_container')['data-markers'].split('},{').count).to eq(n)
    
    0 讨论(0)
  • 2021-02-18 14:18

    This can be done, but requires a change to how you create your markers. You must instruct them to render as images rather than canvas elements:

    new google.maps.Marker({
      position:  latLng,
      animation: google.maps.Animation.DROP,
      name:      business.get('name'),
      id:        business.get('id'),
      optimized: false, // <-- this is the stuff
      title:     business.get('name')
    });
    

    Then in your test, you can find('div[title="Business\ Title"]').click

    If possible, you might want to consider doing this just for a test environment, but that's up to you and your needs.

    Credit: http://blog.mojotech.com/selecting-google-maps-v3-markers-with-selenium-or-jquery/

    Hope this helps!

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