@@ -9227,6 +9227,162 @@ def wait_for_element_not_present(
9227
9227
original_selector=original_selector,
9228
9228
)
9229
9229
9230
+ def wait_for_any_of_elements_visible(self, *args, **kwargs):
9231
+ """Waits for at least one of the elements to be visible.
9232
+ Returns the first element that is found.
9233
+ The input is a list of elements. (Should be CSS selectors or XPath)
9234
+ Optional kwargs include: "timeout" (used by all selectors).
9235
+ Raises an exception if no elements are visible by the timeout.
9236
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9237
+ Examples:
9238
+ self.wait_for_any_of_elements_visible("h1", "h2", "h3")
9239
+ OR
9240
+ self.wait_for_any_of_elements_visible(["h1", "h2", "h3"]) """
9241
+ self.__check_scope()
9242
+ selectors = []
9243
+ timeout = None
9244
+ for kwarg in kwargs:
9245
+ if kwarg == "timeout":
9246
+ timeout = kwargs["timeout"]
9247
+ elif kwarg == "by":
9248
+ pass # Autodetected
9249
+ elif kwarg == "selector" or kwarg == "selectors":
9250
+ selector = kwargs[kwarg]
9251
+ if isinstance(selector, str):
9252
+ selectors.append(selector)
9253
+ elif isinstance(selector, list):
9254
+ selectors_list = selector
9255
+ for selector in selectors_list:
9256
+ if isinstance(selector, str):
9257
+ selectors.append(selector)
9258
+ else:
9259
+ raise Exception('Unknown kwarg: "%s"!' % kwarg)
9260
+ if not timeout:
9261
+ timeout = settings.LARGE_TIMEOUT
9262
+ if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
9263
+ timeout = self.__get_new_timeout(timeout)
9264
+ for arg in args:
9265
+ if isinstance(arg, list):
9266
+ for selector in arg:
9267
+ if isinstance(selector, str):
9268
+ selectors.append(selector)
9269
+ elif isinstance(arg, str):
9270
+ selectors.append(arg)
9271
+ if not selectors:
9272
+ raise Exception("The selectors list was empty!")
9273
+ original_selectors = selectors
9274
+ updated_selectors = []
9275
+ for selector in selectors:
9276
+ by = "css selector"
9277
+ if page_utils.is_xpath_selector(selector):
9278
+ by = "xpath"
9279
+ selector, by = self.__recalculate_selector(selector, by)
9280
+ updated_selectors.append(selector)
9281
+ selectors = updated_selectors
9282
+ if self.__is_cdp_swap_needed():
9283
+ return self.cdp.wait_for_any_of_elements_visible(
9284
+ selectors, timeout=timeout
9285
+ )
9286
+ return page_actions.wait_for_any_of_elements_visible(
9287
+ self.driver,
9288
+ selectors,
9289
+ timeout=timeout,
9290
+ original_selectors=original_selectors,
9291
+ )
9292
+
9293
+ def wait_for_any_of_elements_present(self, *args, **kwargs):
9294
+ """Waits for at least one of the elements to be present.
9295
+ Visibility not required, but element must be in the DOM.
9296
+ Returns the first element that is found.
9297
+ The input is a list of elements. (Should be CSS selectors or XPath)
9298
+ Optional kwargs include: "timeout" (used by all selectors).
9299
+ Raises an exception if no elements are present by the timeout.
9300
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9301
+ Examples:
9302
+ self.wait_for_any_of_elements_present("style", "script")
9303
+ OR
9304
+ self.wait_for_any_of_elements_present(["style", "script"]) """
9305
+ self.__check_scope()
9306
+ selectors = []
9307
+ timeout = None
9308
+ for kwarg in kwargs:
9309
+ if kwarg == "timeout":
9310
+ timeout = kwargs["timeout"]
9311
+ elif kwarg == "by":
9312
+ pass # Autodetected
9313
+ elif kwarg == "selector" or kwarg == "selectors":
9314
+ selector = kwargs[kwarg]
9315
+ if isinstance(selector, str):
9316
+ selectors.append(selector)
9317
+ elif isinstance(selector, list):
9318
+ selectors_list = selector
9319
+ for selector in selectors_list:
9320
+ if isinstance(selector, str):
9321
+ selectors.append(selector)
9322
+ else:
9323
+ raise Exception('Unknown kwarg: "%s"!' % kwarg)
9324
+ if not timeout:
9325
+ timeout = settings.LARGE_TIMEOUT
9326
+ if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
9327
+ timeout = self.__get_new_timeout(timeout)
9328
+ for arg in args:
9329
+ if isinstance(arg, list):
9330
+ for selector in arg:
9331
+ if isinstance(selector, str):
9332
+ selectors.append(selector)
9333
+ elif isinstance(arg, str):
9334
+ selectors.append(arg)
9335
+ if not selectors:
9336
+ raise Exception("The selectors list was empty!")
9337
+ original_selectors = selectors
9338
+ updated_selectors = []
9339
+ for selector in selectors:
9340
+ by = "css selector"
9341
+ if page_utils.is_xpath_selector(selector):
9342
+ by = "xpath"
9343
+ selector, by = self.__recalculate_selector(selector, by)
9344
+ updated_selectors.append(selector)
9345
+ selectors = updated_selectors
9346
+ if self.__is_cdp_swap_needed():
9347
+ return self.cdp.wait_for_any_of_elements_present(
9348
+ selectors, timeout=timeout
9349
+ )
9350
+ return page_actions.wait_for_any_of_elements_present(
9351
+ self.driver,
9352
+ selectors,
9353
+ timeout=timeout,
9354
+ original_selectors=original_selectors,
9355
+ )
9356
+
9357
+ def assert_any_of_elements_visible(self, *args, **kwargs):
9358
+ """Similar to wait_for_any_of_elements_visible(), but returns nothing.
9359
+ As above, raises an exception if none of the set elements are visible.
9360
+ Returns True if successful. Default timeout = SMALL_TIMEOUT.
9361
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9362
+ Examples:
9363
+ self.assert_any_of_elements_visible("h1", "h2", "h3")
9364
+ OR
9365
+ self.assert_any_of_elements_visible(["h1", "h2", "h3"]) """
9366
+ if "timeout" not in kwargs:
9367
+ kwargs["timeout"] = settings.SMALL_TIMEOUT
9368
+ self.wait_for_any_of_elements_visible(*args, **kwargs)
9369
+ return True
9370
+
9371
+ def assert_any_of_elements_present(self, *args, **kwargs):
9372
+ """Similar to wait_for_any_of_elements_present(), but returns nothing.
9373
+ As above, raises an exception if none of the given elements are found.
9374
+ Visibility is not required, but element must exist in the DOM.
9375
+ Returns True if successful. Default timeout = SMALL_TIMEOUT.
9376
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9377
+ Examples:
9378
+ self.assert_any_of_elements_present("h1", "h2", "h3")
9379
+ OR
9380
+ self.assert_any_of_elements_present(["h1", "h2", "h3"]) """
9381
+ if "timeout" not in kwargs:
9382
+ kwargs["timeout"] = settings.SMALL_TIMEOUT
9383
+ self.wait_for_any_of_elements_present(*args, **kwargs)
9384
+ return True
9385
+
9230
9386
def select_all(self, selector, by="css selector", limit=0):
9231
9387
return self.find_elements(selector, by=by, limit=limit)
9232
9388
@@ -9698,6 +9854,7 @@ def assert_elements_present(self, *args, **kwargs):
9698
9854
The input is a list of elements.
9699
9855
Optional kwargs include "by" and "timeout" (used by all selectors).
9700
9856
Raises an exception if any of the elements are not visible.
9857
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9701
9858
Examples:
9702
9859
self.assert_elements_present("head", "style", "script", "body")
9703
9860
OR
@@ -9711,7 +9868,7 @@ def assert_elements_present(self, *args, **kwargs):
9711
9868
timeout = kwargs["timeout"]
9712
9869
elif kwarg == "by":
9713
9870
by = kwargs["by"]
9714
- elif kwarg == "selector":
9871
+ elif kwarg == "selector" or kwarg == "selectors" :
9715
9872
selector = kwargs["selector"]
9716
9873
if isinstance(selector, str):
9717
9874
selectors.append(selector)
@@ -9804,6 +9961,7 @@ def assert_elements(self, *args, **kwargs):
9804
9961
The input is a list of elements.
9805
9962
Optional kwargs include "by" and "timeout" (used by all selectors).
9806
9963
Raises an exception if any of the elements are not visible.
9964
+ Allows flexible inputs (Eg. Multiple args or a list of args)
9807
9965
Examples:
9808
9966
self.assert_elements("h1", "h2", "h3")
9809
9967
OR
@@ -9817,7 +9975,7 @@ def assert_elements(self, *args, **kwargs):
9817
9975
timeout = kwargs["timeout"]
9818
9976
elif kwarg == "by":
9819
9977
by = kwargs["by"]
9820
- elif kwarg == "selector":
9978
+ elif kwarg == "selector" or kwarg == "selectors" :
9821
9979
selector = kwargs["selector"]
9822
9980
if isinstance(selector, str):
9823
9981
selectors.append(selector)
0 commit comments