Skip to content

Commit f5b4f1c

Browse files
author
AutomatedTester
committed
Update find_elements to match spec
1 parent acc7c83 commit f5b4f1c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,17 @@ def find_element(self, by=By.ID, value=None):
677677
"""
678678
if not By.is_valid(by) or not isinstance(value, str):
679679
raise InvalidSelectorException("Invalid locator values passed in")
680-
680+
if by == By.ID:
681+
by = By.CSS_SELECTOR
682+
value = '[id="%s"]' % value
683+
elif by == By.TAG_NAME:
684+
by = By.CSS_SELECTOR
685+
elif by == By.CLASS_NAME:
686+
by = By.CSS_SELECTOR
687+
value = ".%s" % value
688+
elif by == By.NAME:
689+
by = By.CSS_SELECTOR
690+
value = '[name="%s"]' % value
681691
return self.execute(Command.FIND_ELEMENT,
682692
{'using': by, 'value': value})['value']
683693

@@ -693,6 +703,18 @@ def find_elements(self, by=By.ID, value=None):
693703
if not By.is_valid(by) or not isinstance(value, str):
694704
raise InvalidSelectorException("Invalid locator values passed in")
695705

706+
if by == By.ID:
707+
by = By.CSS_SELECTOR
708+
value = '[id="%s"]' % value
709+
elif by == By.TAG_NAME:
710+
by = By.CSS_SELECTOR
711+
elif by == By.CLASS_NAME:
712+
by = By.CSS_SELECTOR
713+
value = ".%s" % value
714+
elif by == By.NAME:
715+
by = By.CSS_SELECTOR
716+
value = '[name="%s"]' % value
717+
696718
return self.execute(Command.FIND_ELEMENTS,
697719
{'using': by, 'value': value})['value']
698720
@property

py/selenium/webdriver/remote/webelement.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,37 @@ def find_element(self, by=By.ID, value=None):
450450
if not By.is_valid(by) or not isinstance(value, str):
451451
raise InvalidSelectorException("Invalid locator values passed in")
452452

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
464+
453465
return self._execute(Command.FIND_CHILD_ELEMENT,
454466
{"using": by, "value": value})['value']
455467

456468
def find_elements(self, by=By.ID, value=None):
457469
if not By.is_valid(by) or not isinstance(value, str):
458470
raise InvalidSelectorException("Invalid locator values passed in")
459471

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
483+
460484
return self._execute(Command.FIND_CHILD_ELEMENTS,
461485
{"using": by, "value": value})['value']
462486

0 commit comments

Comments
 (0)