在 Rails 中使用 Capybara 和 Selenium 测试 Google 地图标记
Testing Google Map Markers with Capybara and Selenium in Rails
我有一个 google 地图页面,可以搜索地址,然后显示 100 英里以内的标记。我正在尝试测试我的标记是否有一个内容 window,当点击使用 Capybara、Selenium 和 Rails 时会弹出该内容。
我收到一条错误消息 "Selenium::WebDriver::Error::ElementNotInteractableError: Element could not be scrolled into view"
有谁知道如何解决这个问题或更好的方法来测试 google 地图标记的弹出内容 window?滚动在 Google 地图中不起作用,所以我假设这就是发生这种情况的原因。
it 'enters in an address for IN Adjusters', js: true do
visit '/maps'
fill_in 'address', with: '4511 W 200 S'
click_button('Search')
sleep(5)
element = find('map#gmimap0')
element.click
expect(page).to have_content("Burke Eric")
end
您可以尝试使用 Capybara 的 visible: false
属性 来寻找地图标记:
element = find('map#gmimap0', visible: false)
这应该允许您调用 click
方法,只要元素在 DOM 中可用。
谢谢!
这里的问题是,技术上 map#gmimap0
元素的高度为 0px,因此驱动程序无法确定实际点击的位置。如果您将 Chrome 与 selenium 一起使用,并且 map#gmimap0
元素有一个大小为(例如 area
元素)的子元素,那么您可以做
find('map#gmimap0 area').click
它可能会工作,但我相信您使用的是带有 selenium 的 Firefox,由于 geckodriver 或 firefox 中的错误,它仍然无法像那样工作。幸运的是,有一种方法可以在任一浏览器中使用,即指定点击偏移量。这导致 selenium 不必担心元素大小,只需单击页面上与元素位置偏移的位置。
find('map#gmimap0').click(x: 10, y: 10) # offset x an y within the size of the marker
我有一个 google 地图页面,可以搜索地址,然后显示 100 英里以内的标记。我正在尝试测试我的标记是否有一个内容 window,当点击使用 Capybara、Selenium 和 Rails 时会弹出该内容。
我收到一条错误消息 "Selenium::WebDriver::Error::ElementNotInteractableError: Element could not be scrolled into view" 有谁知道如何解决这个问题或更好的方法来测试 google 地图标记的弹出内容 window?滚动在 Google 地图中不起作用,所以我假设这就是发生这种情况的原因。
it 'enters in an address for IN Adjusters', js: true do
visit '/maps'
fill_in 'address', with: '4511 W 200 S'
click_button('Search')
sleep(5)
element = find('map#gmimap0')
element.click
expect(page).to have_content("Burke Eric")
end
您可以尝试使用 Capybara 的 visible: false
属性 来寻找地图标记:
element = find('map#gmimap0', visible: false)
这应该允许您调用 click
方法,只要元素在 DOM 中可用。
谢谢!
这里的问题是,技术上 map#gmimap0
元素的高度为 0px,因此驱动程序无法确定实际点击的位置。如果您将 Chrome 与 selenium 一起使用,并且 map#gmimap0
元素有一个大小为(例如 area
元素)的子元素,那么您可以做
find('map#gmimap0 area').click
它可能会工作,但我相信您使用的是带有 selenium 的 Firefox,由于 geckodriver 或 firefox 中的错误,它仍然无法像那样工作。幸运的是,有一种方法可以在任一浏览器中使用,即指定点击偏移量。这导致 selenium 不必担心元素大小,只需单击页面上与元素位置偏移的位置。
find('map#gmimap0').click(x: 10, y: 10) # offset x an y within the size of the marker