Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fix for finding a field by name using a regex

Bug fix for when using a regular expression to fill in a field that is
not visible on the page, i.e. css attributes on the element are set to
"display:none;"
  • Loading branch information...
commit ca8e6c26a48204e9fdb6fc5cd1f82f747c895366 1 parent 004cc24
Nick Anderson authored
View
6 lib/webrat/core/locators/field_named_locator.rb
@@ -11,7 +11,11 @@ def locate
def field_element
field_elements.detect do |field_element|
- field_element["name"] == @value.to_s
+ if @value.is_a?(Regexp)
+ field_element["name"] =~ @value
+ else
+ field_element["name"] == @value.to_s
+ end
end
end
View
15 spec/public/locators/field_named_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
+
+describe "field_named" do
+ it "should work when passed a regular expression for the name" do
+ with_html <<-HTML
+ <html>
+ <form>
+ <input type="text" name="user_1_input">
+ </form>
+ </html>
+ HTML
+ result = field_named(/user_\d_input/).element.attributes['name'].value
+ result.should == "user_1_input"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.