31
31
from selenium .common .exceptions import NoSuchFrameException
32
32
from selenium .common .exceptions import NoSuchWindowException
33
33
from selenium .common .exceptions import StaleElementReferenceException
34
+ from selenium .common .exceptions import TimeoutException
34
35
from selenium .webdriver .common .by import By
35
36
from selenium .webdriver .common .action_chains import ActionChains
36
37
from seleniumbase .config import settings
@@ -384,7 +385,12 @@ def wait_for_element_visible(
384
385
385
386
386
387
def wait_for_text_visible (
387
- driver , text , selector , by = By .CSS_SELECTOR , timeout = settings .LARGE_TIMEOUT
388
+ driver ,
389
+ text ,
390
+ selector ,
391
+ by = By .CSS_SELECTOR ,
392
+ timeout = settings .LARGE_TIMEOUT ,
393
+ browser = None
388
394
):
389
395
"""
390
396
Searches for the specified element by the given selector. Returns the
@@ -412,11 +418,21 @@ def wait_for_text_visible(
412
418
try :
413
419
element = driver .find_element (by = by , value = selector )
414
420
is_present = True
415
- if element .is_displayed () and text in element .text :
416
- return element
421
+ if browser == "safari" :
422
+ if (
423
+ element .is_displayed ()
424
+ and text in element .get_attribute ("innerText" )
425
+ ):
426
+ return element
427
+ else :
428
+ element = None
429
+ raise Exception ()
417
430
else :
418
- element = None
419
- raise Exception ()
431
+ if element .is_displayed () and text in element .text :
432
+ return element
433
+ else :
434
+ element = None
435
+ raise Exception ()
420
436
except Exception :
421
437
now_ms = time .time () * 1000.0
422
438
if now_ms >= stop_ms :
@@ -443,7 +459,12 @@ def wait_for_text_visible(
443
459
444
460
445
461
def wait_for_exact_text_visible (
446
- driver , text , selector , by = By .CSS_SELECTOR , timeout = settings .LARGE_TIMEOUT
462
+ driver ,
463
+ text ,
464
+ selector ,
465
+ by = By .CSS_SELECTOR ,
466
+ timeout = settings .LARGE_TIMEOUT ,
467
+ browser = None
447
468
):
448
469
"""
449
470
Searches for the specified element by the given selector. Returns the
@@ -471,11 +492,25 @@ def wait_for_exact_text_visible(
471
492
try :
472
493
element = driver .find_element (by = by , value = selector )
473
494
is_present = True
474
- if element .is_displayed () and text .strip () == element .text .strip ():
475
- return element
495
+ if browser == "safari" :
496
+ if (
497
+ element .is_displayed ()
498
+ and text .strip () == element .get_attribute (
499
+ "innerText" ).strip ()
500
+ ):
501
+ return element
502
+ else :
503
+ element = None
504
+ raise Exception ()
476
505
else :
477
- element = None
478
- raise Exception ()
506
+ if (
507
+ element .is_displayed ()
508
+ and text .strip () == element .text .strip ()
509
+ ):
510
+ return element
511
+ else :
512
+ element = None
513
+ raise Exception ()
479
514
except Exception :
480
515
now_ms = time .time () * 1000.0
481
516
if now_ms >= stop_ms :
@@ -958,7 +993,7 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
958
993
try :
959
994
driver .switch_to .frame (frame )
960
995
return True
961
- except NoSuchFrameException :
996
+ except ( NoSuchFrameException , TimeoutException ) :
962
997
if type (frame ) is str :
963
998
by = None
964
999
if page_utils .is_xpath_selector (frame ):
0 commit comments