Skip to content

Commit dd0cc3a

Browse files
committed
rb - update w3c getElementAttribute
1 parent 39208b1 commit dd0cc3a

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

rb/lib/selenium/webdriver/remote/w3c_bridge.rb

+34-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ module Remote
3131
class W3CBridge
3232
include BridgeHelper
3333

34+
BOOLEAN_ATTRIBUTES = %i[async autofocus autoplay checked compact complete controls
35+
declare defaultchecked defaultselected defer disabled draggable ended
36+
formnovalidate hidden indeterminate iscontenteditable ismap itemscope
37+
loop multiple muted nohref noresize noshade novalidate nowrap open
38+
paused pubdate readonly required reversed scoped seamless seeking
39+
selected truespeed willvalidate].freeze
40+
3441
# TODO: constant shouldn't be modified in class
3542
COMMANDS = {}
3643

@@ -518,12 +525,37 @@ def element_tag_name(element)
518525
execute :getElementTagName, id: element.values.first
519526
end
520527

528+
# TODO - Replace implementation with atom
521529
def element_attribute(element, name)
522-
execute :getElementAttribute, id: element.values.first, name: name
530+
name = name.to_sym
531+
532+
if name == :style
533+
return execute_script("return arguments[0].style.cssText", element)
534+
end
535+
536+
if BOOLEAN_ATTRIBUTES.include? name
537+
return execute :getElementAttribute, id: element.values.first, name: name
538+
end
539+
540+
property_value = execute :getElementProperty, id: element.values.first, name: name
541+
g return property_value if name == :value
542+
return property_value if property_value &&
543+
!(property_value.respond_to?(:empty?) && property_value.empty?)
544+
545+
attribute_value = execute :getElementAttribute, id: element.values.first, name: name
546+
return nil if attribute_value.nil?
547+
548+
# Verify attribute not the browser default
549+
has_attribute = execute_script("return arguments[0].hasAttribute(arguments[1])", element, name)
550+
attribute_value if has_attribute
551+
end
552+
553+
def element_property(element, name)
554+
execute :getElementProperty, id: element.values.first, name: name
523555
end
524556

525557
def element_value(element)
526-
execute :getElementProperty, id: element.values.first, name: 'value'
558+
element_property element, 'value'
527559
end
528560

529561
def element_text(element)

rb/spec/integration/selenium/webdriver/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Object
3636
RSpec.configure do |c|
3737
c.include(WebDriver::SpecSupport::Helpers)
3838
c.before(:suite) do
39-
$DEBUG = ENV['DEBUG'] == 'true'
39+
$DEBUG ||= ENV['DEBUG'] == 'true'
4040
GlobalTestEnv.remote_server.start if GlobalTestEnv.driver == :remote
4141
end
4242

0 commit comments

Comments
 (0)