Skip to content

Commit 8b47d0a

Browse files
lmtierneytitusfortner
authored andcommitted
rb: add property webelement method
Signed-off-by: Titus Fortner <titusfortner@gmail.com>
1 parent 183c51d commit 8b47d0a

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

rb/lib/selenium/webdriver/common/element.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ def attribute(name)
118118
bridge.element_attribute self, name
119119
end
120120

121+
#
122+
# Get the value of a the given property with the same name of the element. If the value is not
123+
# set, nil is returned.
124+
#
125+
# @param [String]
126+
# property name
127+
# @return [String,nil]
128+
# property value
129+
#
130+
131+
def property(name)
132+
bridge.element_property self, name
133+
end
134+
121135
#
122136
# Get the text content of this element
123137
#

rb/lib/selenium/webdriver/remote/bridge.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ def element_attribute(element, name)
541541
execute :getElementAttribute, id: element.ref, name: name
542542
end
543543

544+
# Backwards compatibility for w3c
545+
def element_property(element, name)
546+
execute_script 'return arguments[0][arguments[1]]', element, name
547+
end
548+
544549
def element_value(element)
545550
execute :getElementValue, id: element
546551
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def element_attribute(element, name)
525525
end
526526

527527
def element_property(element, name)
528-
execute :getElementProperty, id: element.values.first, name: name
528+
execute :getElementProperty, id: element.ref.values.first, name: name
529529
end
530530

531531
def element_value(element)

rb/spec/integration/selenium/webdriver/element_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ module WebDriver
9494
expect(driver.find_element(id: 'withText').attribute('nonexistent')).to be_nil
9595
end
9696

97+
not_compliant_on browser: :edge do
98+
it 'should get property value' do
99+
driver.navigate.to url_for('formPage.html')
100+
expect(driver.find_element(id: 'withText').property('nodeName')).to eq('TEXTAREA')
101+
end
102+
end
103+
97104
it 'should clear' do
98105
driver.navigate.to url_for('formPage.html')
99106
driver.find_element(id: 'withText').clear

0 commit comments

Comments
 (0)