Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for optional Element#style property argument, which allow…

…s to get specific css style attribute value.
  • Loading branch information...
commit 6723e8762302ab38631c79552ec3aaba61b0db2c 1 parent bd128a9
@jarmo jarmo authored
Showing with 28 additions and 2 deletions.
  1. +9 −2 lib/watir-classic/element.rb
  2. +19 −0 spec/element_spec.rb
View
11 lib/watir-classic/element.rb
@@ -113,9 +113,16 @@ def send_keys(*keys)
end
# return the css style as a string
- def style
+ def style(property=nil)
assert_exists
- ole_object.style.cssText
+ css = ole_object.style.cssText
+
+ if property
+ properties = Hash[css.downcase.split(";").map { |p| p.split(":").map(&:strip) }]
+ properties[property]
+ else
+ css
+ end
end
# Return the innerText of the object or an empty string if the object is
View
19 spec/element_spec.rb
@@ -0,0 +1,19 @@
+# encoding: utf-8
+require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
+
+describe "Element" do
+
+ before :each do
+ browser.goto(WatirSpec.url_for("non_control_elements.html"))
+ end
+
+ describe "#style" do
+ it "returns the style attribute if the property exists" do
+ el = browser.div(:id, 'best_language')
+ el.style("color").should == "red"
+ el.style("text-decoration").should == "underline"
+ el.style("cursor").should == "pointer"
+ end
+ end
+
+end

0 comments on commit 6723e87

Please sign in to comment.
Something went wrong with that request. Please try again.