14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
+ import warnings
17
18
from typing import Dict
18
19
from typing import List
19
20
from typing import NoReturn
30
31
def with_tag_name (tag_name : str ) -> "RelativeBy" :
31
32
"""Start searching for relative objects using a tag name.
32
33
33
- Note: This method may be removed in future versions, please use
34
- `locate_with` instead.
35
-
36
- :Args:
37
- - tag_name: the DOM tag of element to start searching.
38
- :Returns:
39
- - RelativeBy: use this object to create filters within a
40
- `find_elements` call.
34
+ Parameters:
35
+ ----------
36
+ tag_name : str
37
+ The DOM tag of element to start searching.
38
+
39
+ Returns:
40
+ --------
41
+ RelativeBy
42
+ Use this object to create filters within a `find_elements` call.
43
+
44
+ Raises:
45
+ -------
46
+ WebDriverException
47
+ If `tag_name` is None.
48
+
49
+ Notes:
50
+ ------
51
+ - This method is deprecated and may be removed in future versions.
52
+ - Please use `locate_with` instead.
41
53
"""
54
+ warnings .warn (
55
+ "This method is deprecated and may be removed in future versions. " "Please use `locate_with` instead."
56
+ )
42
57
if not tag_name :
43
58
raise WebDriverException ("tag_name can not be null" )
44
59
return RelativeBy ({By .CSS_SELECTOR : tag_name })
@@ -47,12 +62,23 @@ def with_tag_name(tag_name: str) -> "RelativeBy":
47
62
def locate_with (by : ByType , using : str ) -> "RelativeBy" :
48
63
"""Start searching for relative objects your search criteria with By.
49
64
50
- :Args:
51
- - by: The value from `By` passed in.
52
- - using: search term to find the element with.
53
- :Returns:
54
- - RelativeBy: use this object to create filters within a
55
- `find_elements` call.
65
+ Parameters:
66
+ ----------
67
+ by : ByType
68
+ The method to find the element.
69
+
70
+ using : str
71
+ The value from `By` passed in.
72
+
73
+ Returns:
74
+ --------
75
+ RelativeBy
76
+ Use this object to create filters within a `find_elements` call.
77
+
78
+ Example:
79
+ --------
80
+ >>> lowest = driver.find_element(By.ID, "below")
81
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").above(lowest))
56
82
"""
57
83
assert by is not None , "Please pass in a by argument"
58
84
assert using is not None , "Please pass in a using argument"
@@ -65,13 +91,12 @@ class RelativeBy:
65
91
function to create it.
66
92
67
93
Example:
68
- lowest = driver.find_element(By.ID, "below")
69
-
70
- elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").above(lowest))
71
-
72
- ids = [el.get_attribute('id') for el in elements]
73
- assert "above" in ids
74
- assert "mid" in ids
94
+ --------
95
+ >>> lowest = driver.find_element(By.ID, "below")
96
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").above(lowest))
97
+ >>> ids = [el.get_attribute('id') for el in elements]
98
+ >>> assert "above" in ids
99
+ >>> assert "mid" in ids
75
100
"""
76
101
77
102
LocatorType = Dict [ByType , str ]
@@ -80,9 +105,13 @@ def __init__(self, root: Optional[Dict[ByType, str]] = None, filters: Optional[L
80
105
"""Creates a new RelativeBy object. It is preferred if you use the
81
106
`locate_with` method as this signature could change.
82
107
83
- :Args:
84
- root - A dict with `By` enum as the key and the search query as the value
85
- filters - A list of the filters that will be searched. If none are passed
108
+ Attributes:
109
+ ----------
110
+ root : Dict[By, str]
111
+ - A dict with `By` enum as the key and the search query as the value
112
+
113
+ filters : List
114
+ - A list of the filters that will be searched. If none are passed
86
115
in please use the fluent API on the object to create the filters
87
116
"""
88
117
self .root = root
@@ -97,8 +126,24 @@ def above(self, element_or_locator: None = None) -> "NoReturn": ...
97
126
def above (self , element_or_locator : Union [WebElement , LocatorType , None ] = None ) -> "RelativeBy" :
98
127
"""Add a filter to look for elements above.
99
128
100
- :Args:
101
- - element_or_locator: Element to look above
129
+ Parameters:
130
+ ----------
131
+ element_or_locator : Union[WebElement, Dict, None]
132
+ Element to look above
133
+
134
+ Returns:
135
+ --------
136
+ RelativeBy
137
+
138
+ Raises:
139
+ -------
140
+ WebDriverException
141
+ If `element_or_locator` is None.
142
+
143
+ Example:
144
+ --------
145
+ >>> lowest = driver.find_element(By.ID, "below")
146
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").above(lowest))
102
147
"""
103
148
if not element_or_locator :
104
149
raise WebDriverException ("Element or locator must be given when calling above method" )
@@ -115,8 +160,24 @@ def below(self, element_or_locator: None = None) -> "NoReturn": ...
115
160
def below (self , element_or_locator : Union [WebElement , Dict , None ] = None ) -> "RelativeBy" :
116
161
"""Add a filter to look for elements below.
117
162
118
- :Args:
119
- - element_or_locator: Element to look below
163
+ Parameters:
164
+ ----------
165
+ element_or_locator : Union[WebElement, Dict, None]
166
+ Element to look below
167
+
168
+ Returns:
169
+ --------
170
+ RelativeBy
171
+
172
+ Raises:
173
+ -------
174
+ WebDriverException
175
+ If `element_or_locator` is None.
176
+
177
+ Example:
178
+ --------
179
+ >>> highest = driver.find_element(By.ID, "high")
180
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").below(highest))
120
181
"""
121
182
if not element_or_locator :
122
183
raise WebDriverException ("Element or locator must be given when calling below method" )
@@ -133,8 +194,24 @@ def to_left_of(self, element_or_locator: None = None) -> "NoReturn": ...
133
194
def to_left_of (self , element_or_locator : Union [WebElement , Dict , None ] = None ) -> "RelativeBy" :
134
195
"""Add a filter to look for elements to the left of.
135
196
136
- :Args:
137
- - element_or_locator: Element to look to the left of
197
+ Parameters:
198
+ ----------
199
+ element_or_locator : Union[WebElement, Dict, None]
200
+ Element to look to the left of
201
+
202
+ Returns:
203
+ --------
204
+ RelativeBy
205
+
206
+ Raises:
207
+ -------
208
+ WebDriverException
209
+ If `element_or_locator` is None.
210
+
211
+ Example:
212
+ --------
213
+ >>> right = driver.find_element(By.ID, "right")
214
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").to_left_of(right))
138
215
"""
139
216
if not element_or_locator :
140
217
raise WebDriverException ("Element or locator must be given when calling to_left_of method" )
@@ -151,8 +228,24 @@ def to_right_of(self, element_or_locator: None = None) -> "NoReturn": ...
151
228
def to_right_of (self , element_or_locator : Union [WebElement , Dict , None ] = None ) -> "RelativeBy" :
152
229
"""Add a filter to look for elements right of.
153
230
154
- :Args:
155
- - element_or_locator: Element to look right of
231
+ Parameters:
232
+ ----------
233
+ element_or_locator : Union[WebElement, Dict, None]
234
+ Element to look right of
235
+
236
+ Returns:
237
+ --------
238
+ RelativeBy
239
+
240
+ Raises:
241
+ -------
242
+ WebDriverException
243
+ If `element_or_locator` is None.
244
+
245
+ Example:
246
+ --------
247
+ >>> left = driver.find_element(By.ID, "left")
248
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").to_right_of(left))
156
249
"""
157
250
if not element_or_locator :
158
251
raise WebDriverException ("Element or locator must be given when calling to_right_of method" )
@@ -241,9 +334,28 @@ def near(self, element_or_locator: None = None, distance: int = 50) -> "NoReturn
241
334
def near (self , element_or_locator : Union [WebElement , LocatorType , None ] = None , distance : int = 50 ) -> "RelativeBy" :
242
335
"""Add a filter to look for elements near.
243
336
244
- :Args:
245
- - element_or_locator: Element to look near by the element or within a distance
246
- - distance: distance in pixel
337
+ Parameters:
338
+ ----------
339
+ element_or_locator : Union[WebElement, Dict, None]
340
+ Element to look near by the element or within a distance
341
+
342
+ distance : int
343
+ Distance in pixel
344
+
345
+ Returns:
346
+ --------
347
+ RelativeBy
348
+
349
+ Raises:
350
+ -------
351
+ WebDriverException
352
+ - If `element_or_locator` is None
353
+ - If `distance` is less than or equal to 0.
354
+
355
+ Example:
356
+ --------
357
+ >>> near = driver.find_element(By.ID, "near")
358
+ >>> elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "p").near(near, 50))
247
359
"""
248
360
if not element_or_locator :
249
361
raise WebDriverException ("Element or locator must be given when calling near method" )
0 commit comments