From c2034fd193c75d7eeba21edcd06609facc4672b7 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 18 Jul 2016 13:17:22 -0700 Subject: [PATCH] Make frame finder a selector --- lib/capybara/selector.rb | 8 ++++++++ lib/capybara/session.rb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index f56fa532..1c572034 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -381,3 +381,11 @@ Capybara.add_selector(:table) do xpath end end + +Capybara.add_selector(:frame) do + xpath do |locator| + xpath = XPath.descendant(:iframe) + xpath = xpath[XPath.attr(:id).equals(locator.to_s) | XPath.attr(:name).equals(locator)] unless locator.nil? + xpath + end +end \ No newline at end of file diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 9a5cbbd7..1f06d5d2 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -345,9 +345,9 @@ module Capybara when Capybara::Node::Element locator when String - find(:xpath, XPath.descendant(:iframe)[XPath.attr(:id).equals(locator) | XPath.attr(:name).equals(locator)].to_xpath(:exact)) + find(:frame, locator) when Integer - all(:css, 'iframe', minimum: locator+1)[locator] + all(:frame, minimum: locator+1)[locator] else raise ArgumentError end