Skip to content

Commit a9bc94b

Browse files
committed
rb - change w3c element id processing
1 parent cb4f29e commit a9bc94b

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

rb/lib/selenium/webdriver/common/bridge_helper.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def unwrap_script_result(arg)
3131
when Array
3232
arg.map { |e| unwrap_script_result(e) }
3333
when Hash
34-
id = element_id_from(arg)
35-
return Element.new(self, id) if id
34+
element_id = element_id_from(arg)
35+
element_id = arg if self.is_a?(Remote::W3CBridge) && element_id
36+
return Element.new(self, element_id) if element_id
3637
arg.each { |k, v| arg[k] = unwrap_script_result(v) }
3738
else
3839
arg

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ def to_json(*)
292292
#
293293

294294
def as_json(*)
295-
{
296-
:ELEMENT => @id,
297-
'element-6066-11e4-a52e-4f735466cecf' => @id
298-
}
295+
@id.is_a?(Hash) ? @id : {:ELEMENT => @id}
299296
end
300297

301298
private

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

+17-18
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def delete_all_cookies
396396
#
397397

398398
def click_element(element)
399-
execute :elementClick, id: element
399+
execute :elementClick, id: element.values.first
400400
end
401401

402402
def click
@@ -436,11 +436,11 @@ def send_keys_to_active_element(keys)
436436

437437
# TODO: - Implement file verification
438438
def send_keys_to_element(element, keys)
439-
execute :elementSendKeys, {id: element}, {value: keys.join('').split(//)}
439+
execute :elementSendKeys, {id: element.values.first}, {value: keys.join('').split(//)}
440440
end
441441

442442
def clear_element(element)
443-
execute :elementClear, id: element
443+
execute :elementClear, id: element.values.first
444444
end
445445

446446
def submit_element(element)
@@ -450,7 +450,7 @@ def submit_element(element)
450450
end
451451

452452
def drag_element(element, right_by, down_by)
453-
execute :dragElement, {id: element}, {x: right_by, y: down_by}
453+
execute :dragElement, {id: element.values.first}, {x: right_by, y: down_by}
454454
end
455455

456456
def touch_single_tap(element)
@@ -511,23 +511,23 @@ def screen_orientation
511511
#
512512

513513
def element_tag_name(element)
514-
execute :getElementTagName, id: element
514+
execute :getElementTagName, id: element.values.first
515515
end
516516

517517
def element_attribute(element, name)
518-
execute :getElementAttribute, id: element, name: name
518+
execute :getElementAttribute, id: element.values.first, name: name
519519
end
520520

521521
def element_value(element)
522-
execute :getElementProperty, id: element, name: 'value'
522+
execute :getElementProperty, id: element.values.first, name: 'value'
523523
end
524524

525525
def element_text(element)
526-
execute :getElementText, id: element
526+
execute :getElementText, id: element.values.first
527527
end
528528

529529
def element_location(element)
530-
data = execute :getElementRect, id: element
530+
data = execute :getElementRect, id: element.values.first
531531

532532
Point.new data['x'], data['y']
533533
end
@@ -538,27 +538,27 @@ def element_location_once_scrolled_into_view(element)
538538
end
539539

540540
def element_size(element)
541-
data = execute :getElementRect, id: element
541+
data = execute :getElementRect, id: element.values.first
542542

543543
Dimension.new data['width'], data['height']
544544
end
545545

546546
def element_enabled?(element)
547-
execute :isElementEnabled, id: element
547+
execute :isElementEnabled, id: element.values.first
548548
end
549549

550550
def element_selected?(element)
551-
execute :isElementSelected, id: element
551+
execute :isElementSelected, id: element.values.first
552552
end
553553

554554
def element_displayed?(element)
555555
jwp = Selenium::WebDriver::Remote::Bridge::COMMANDS[:isElementDisplayed]
556556
self.class.command(:isElementDisplayed, jwp.first, jwp.last)
557-
execute :isElementDisplayed, id: element
557+
execute :isElementDisplayed, id: element.values.first
558558
end
559559

560560
def element_value_of_css_property(element, prop)
561-
execute :getElementCssValue, id: element, property_name: prop
561+
execute :getElementCssValue, id: element.values.first, property_name: prop
562562
end
563563

564564
#
@@ -575,19 +575,18 @@ def find_element_by(how, what, parent = nil)
575575
how, what = convert_locators(how, what)
576576

577577
id = if parent
578-
execute :findChildElement, {id: parent}, {using: how, value: what}
578+
execute :findChildElement, {id: parent.values.first}, {using: how, value: what}
579579
else
580580
execute :findElement, {}, {using: how, value: what}
581581
end
582-
583-
Element.new self, element_id_from(id)
582+
Element.new self, id
584583
end
585584

586585
def find_elements_by(how, what, parent = nil)
587586
how, what = convert_locators(how, what)
588587

589588
ids = if parent
590-
execute :findChildElements, {id: parent}, {using: how, value: what}
589+
execute :findChildElements, {id: parent.values.first}, {using: how, value: what}
591590
else
592591
execute :findElements, {}, {using: how, value: what}
593592
end

0 commit comments

Comments
 (0)