Skip to content

Commit 61e866d

Browse files
author
AutomatedTester
committed
Have find_elements match spec when it has a spec compliant browser
1 parent 3cb0af8 commit 61e866d

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def start_session(self, desired_capabilities, browser_profile=None):
138138
self.session_id = response['sessionId']
139139
self.capabilities = response['value']
140140

141-
self.capabilities["marionette"] = desired_capabilities.get("marionette", False)
141+
self.capabilities["w3c"] = desired_capabilities.get("marionette", False)
142142

143143
def _wrap_value(self, value):
144144
if isinstance(value, dict):
@@ -157,7 +157,7 @@ def create_web_element(self, element_id):
157157
"""
158158
Creates a web element with the specified element_id.
159159
"""
160-
return WebElement(self, element_id)
160+
return WebElement(self, element_id, w3c=self.capabilities['w3c'])
161161

162162
def _unwrap_value(self, value):
163163
if isinstance(value, dict) and ('ELEMENT' in value or 'element-6066-11e4-a52e-4f735466cecf' in value):
@@ -503,7 +503,7 @@ def maximize_window(self):
503503
Maximizes the current window that webdriver is using
504504
"""
505505
command = Command.MAXIMIZE_WINDOW
506-
if self.capabilities['marionette'] == True:
506+
if self.capabilities['w3c'] == True:
507507
command = Command.W3C_MAXIMIZE_WINDOW
508508
self.execute(command, {"windowHandle": "current"})
509509

@@ -641,7 +641,7 @@ def implicitly_wait(self, time_to_wait):
641641
:Usage:
642642
driver.implicitly_wait(30)
643643
"""
644-
if self.capabilities["marionette"] == True:
644+
if self.capabilities["w3c"] == True:
645645
self.execute(Command.SET_TIMEOUTS,
646646
{'ms': float(time_to_wait) * 1000, 'type':'implicit'})
647647
else:
@@ -658,7 +658,7 @@ def set_script_timeout(self, time_to_wait):
658658
:Usage:
659659
driver.set_script_timeout(30)
660660
"""
661-
if self.capabilities["marionette"] == True:
661+
if self.capabilities["w3c"] == True:
662662
self.execute(Command.SET_TIMEOUTS,
663663
{'ms': float(time_to_wait) * 1000, 'type':'script'})
664664
else:
@@ -690,17 +690,18 @@ def find_element(self, by=By.ID, value=None):
690690
"""
691691
if not By.is_valid(by) or not isinstance(value, str):
692692
raise InvalidSelectorException("Invalid locator values passed in")
693-
if by == By.ID:
694-
by = By.CSS_SELECTOR
695-
value = '[id="%s"]' % value
696-
elif by == By.TAG_NAME:
697-
by = By.CSS_SELECTOR
698-
elif by == By.CLASS_NAME:
699-
by = By.CSS_SELECTOR
700-
value = ".%s" % value
701-
elif by == By.NAME:
702-
by = By.CSS_SELECTOR
703-
value = '[name="%s"]' % value
693+
if self.capabilities['w3c'] == True:
694+
if by == By.ID:
695+
by = By.CSS_SELECTOR
696+
value = '[id="%s"]' % value
697+
elif by == By.TAG_NAME:
698+
by = By.CSS_SELECTOR
699+
elif by == By.CLASS_NAME:
700+
by = By.CSS_SELECTOR
701+
value = ".%s" % value
702+
elif by == By.NAME:
703+
by = By.CSS_SELECTOR
704+
value = '[name="%s"]' % value
704705
return self.execute(Command.FIND_ELEMENT,
705706
{'using': by, 'value': value})['value']
706707

@@ -715,18 +716,18 @@ def find_elements(self, by=By.ID, value=None):
715716
"""
716717
if not By.is_valid(by) or not isinstance(value, str):
717718
raise InvalidSelectorException("Invalid locator values passed in")
718-
719-
if by == By.ID:
720-
by = By.CSS_SELECTOR
721-
value = '[id="%s"]' % value
722-
elif by == By.TAG_NAME:
723-
by = By.CSS_SELECTOR
724-
elif by == By.CLASS_NAME:
725-
by = By.CSS_SELECTOR
726-
value = ".%s" % value
727-
elif by == By.NAME:
728-
by = By.CSS_SELECTOR
729-
value = '[name="%s"]' % value
719+
if self.capabilities['w3c'] == True:
720+
if by == By.ID:
721+
by = By.CSS_SELECTOR
722+
value = '[id="%s"]' % value
723+
elif by == By.TAG_NAME:
724+
by = By.CSS_SELECTOR
725+
elif by == By.CLASS_NAME:
726+
by = By.CSS_SELECTOR
727+
value = ".%s" % value
728+
elif by == By.NAME:
729+
by = By.CSS_SELECTOR
730+
value = '[name="%s"]' % value
730731

731732
return self.execute(Command.FIND_ELEMENTS,
732733
{'using': by, 'value': value})['value']
@@ -791,7 +792,7 @@ def set_window_size(self, width, height, windowHandle='current'):
791792
driver.set_window_size(800,600)
792793
"""
793794
command = Command.SET_WINDOW_SIZE
794-
if self.capabilities["marionette"] == True:
795+
if self.capabilities["w3c"] == True:
795796
command = Command.W3C_SET_WINDOW_SIZE
796797
self.execute(command, {'width': int(width), 'height': int(height),
797798
'windowHandle': windowHandle})
@@ -804,7 +805,7 @@ def get_window_size(self, windowHandle='current'):
804805
driver.get_window_size()
805806
"""
806807
command = Command.GET_WINDOW_SIZE
807-
if self.capabilities['marionette'] == True:
808+
if self.capabilities['w3c'] == True:
808809
command = Command.W3C_GET_WINDOW_SIZE
809810
size = self.execute(command,
810811
{'windowHandle': windowHandle})

py/selenium/webdriver/remote/webelement.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class WebElement(object):
4949
``StaleElementReferenceException`` is thrown, and all future calls to this
5050
instance will fail."""
5151

52-
def __init__(self, parent, id_):
52+
def __init__(self, parent, id_, w3c=False):
5353
self._parent = parent
5454
self._id = id_
55+
self._w3c = w3c
5556

5657
@property
5758
def tag_name(self):
@@ -450,17 +451,18 @@ def find_element(self, by=By.ID, value=None):
450451
if not By.is_valid(by) or not isinstance(value, str):
451452
raise InvalidSelectorException("Invalid locator values passed in")
452453

453-
if by == By.ID:
454-
by = By.CSS_SELECTOR
455-
value = '[id="%s"]' % value
456-
elif by == By.TAG_NAME:
457-
by = By.CSS_SELECTOR
458-
elif by == By.CLASS_NAME:
459-
by = By.CSS_SELECTOR
460-
value = ".%s" % value
461-
elif by == By.NAME:
462-
by = By.CSS_SELECTOR
463-
value = '[name="%s"]' % value
454+
if self._w3c:
455+
if by == By.ID:
456+
by = By.CSS_SELECTOR
457+
value = '[id="%s"]' % value
458+
elif by == By.TAG_NAME:
459+
by = By.CSS_SELECTOR
460+
elif by == By.CLASS_NAME:
461+
by = By.CSS_SELECTOR
462+
value = ".%s" % value
463+
elif by == By.NAME:
464+
by = By.CSS_SELECTOR
465+
value = '[name="%s"]' % value
464466

465467
return self._execute(Command.FIND_CHILD_ELEMENT,
466468
{"using": by, "value": value})['value']
@@ -469,17 +471,18 @@ def find_elements(self, by=By.ID, value=None):
469471
if not By.is_valid(by) or not isinstance(value, str):
470472
raise InvalidSelectorException("Invalid locator values passed in")
471473

472-
if by == By.ID:
473-
by = By.CSS_SELECTOR
474-
value = '[id="%s"]' % value
475-
elif by == By.TAG_NAME:
476-
by = By.CSS_SELECTOR
477-
elif by == By.CLASS_NAME:
478-
by = By.CSS_SELECTOR
479-
value = ".%s" % value
480-
elif by == By.NAME:
481-
by = By.CSS_SELECTOR
482-
value = '[name="%s"]' % value
474+
if self._w3c:
475+
if by == By.ID:
476+
by = By.CSS_SELECTOR
477+
value = '[id="%s"]' % value
478+
elif by == By.TAG_NAME:
479+
by = By.CSS_SELECTOR
480+
elif by == By.CLASS_NAME:
481+
by = By.CSS_SELECTOR
482+
value = ".%s" % value
483+
elif by == By.NAME:
484+
by = By.CSS_SELECTOR
485+
value = '[name="%s"]' % value
483486

484487
return self._execute(Command.FIND_CHILD_ELEMENTS,
485488
{"using": by, "value": value})['value']

0 commit comments

Comments
 (0)