From 5ca9b25685337934f4d244766e007ca233341f6d Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 11 Sep 2018 11:15:07 -0700 Subject: [PATCH] Only FF needs the frame workaround --- lib/capybara/selenium/driver.rb | 5 +---- .../selenium/driver_specializations/marionette_driver.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index 97ee8d06..0a4587a0 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -143,11 +143,8 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base handles.clear browser.switch_to.default_content when :parent - # would love to use browser.switch_to.parent_frame here - # but it has an issue if the current frame is removed from within it handles.pop - browser.switch_to.default_content - handles.each { |fh| browser.switch_to.frame(fh) } + browser.switch_to.parent_frame else handles << frame.native browser.switch_to.frame(frame.native) diff --git a/lib/capybara/selenium/driver_specializations/marionette_driver.rb b/lib/capybara/selenium/driver_specializations/marionette_driver.rb index a8116aa7..e0144c7d 100644 --- a/lib/capybara/selenium/driver_specializations/marionette_driver.rb +++ b/lib/capybara/selenium/driver_specializations/marionette_driver.rb @@ -32,6 +32,15 @@ module Capybara::Selenium::Driver::MarionetteDriver # No modal was opened - page has refreshed - ignore end + def switch_to_frame(frame) + return super unless frame == :parent + # geckodriver/firefox has an issue if the current frame is removed from within it + # so we have to move to the default_content and iterate back through the frames + handles = @frame_handles[current_window_handle] + browser.switch_to.default_content + handles.tap(&:pop).each { |fh| browser.switch_to.frame(fh) } + end + private def build_node(native_node)