Skip to content

Commit d53d79e

Browse files
committed
[py] convert selectors for finding elements in shadow dom
1 parent a2b06e0 commit d53d79e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

py/selenium/webdriver/remote/shadowroot.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,35 @@ def __repr__(self):
4444
)
4545

4646
def find_element(self, by: By = By.ID, value: str = None):
47+
if by == By.ID:
48+
by = By.CSS_SELECTOR
49+
value = '[id="%s"]' % value
50+
elif by == By.TAG_NAME:
51+
by = By.CSS_SELECTOR
52+
elif by == By.CLASS_NAME:
53+
by = By.CSS_SELECTOR
54+
value = ".%s" % value
55+
elif by == By.NAME:
56+
by = By.CSS_SELECTOR
57+
value = '[name="%s"]' % value
58+
4759
return self._execute(
4860
Command.FIND_ELEMENT_FROM_SHADOW_ROOT, {"using": by, "value": value}
4961
)["value"]
5062

5163
def find_elements(self, by: By = By.ID, value: str = None):
64+
if by == By.ID:
65+
by = By.CSS_SELECTOR
66+
value = '[id="%s"]' % value
67+
elif by == By.TAG_NAME:
68+
by = By.CSS_SELECTOR
69+
elif by == By.CLASS_NAME:
70+
by = By.CSS_SELECTOR
71+
value = ".%s" % value
72+
elif by == By.NAME:
73+
by = By.CSS_SELECTOR
74+
value = '[name="%s"]' % value
75+
5276
return self._execute(
5377
Command.FIND_ELEMENTS_FROM_SHADOW_ROOT, {"using": by, "value": value}
5478
)["value"]

0 commit comments

Comments
 (0)