@@ -39,8 +39,8 @@ def is_element_present(driver, selector, by=By.CSS_SELECTOR):
39
39
Returns whether the specified element selector is present on the page.
40
40
@Params
41
41
driver - the webdriver object (required)
42
- selector - the locator that is used (required)
43
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
42
+ selector - the locator for identifying the page element (required)
43
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
44
44
@Returns
45
45
Boolean (is element present)
46
46
"""
@@ -56,8 +56,8 @@ def is_element_visible(driver, selector, by=By.CSS_SELECTOR):
56
56
Returns whether the specified element selector is visible on the page.
57
57
@Params
58
58
driver - the webdriver object (required)
59
- selector - the locator that is used (required)
60
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
59
+ selector - the locator for identifying the page element (required)
60
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
61
61
@Returns
62
62
Boolean (is element visible)
63
63
"""
@@ -74,8 +74,8 @@ def is_text_visible(driver, text, selector, by=By.CSS_SELECTOR):
74
74
@Params
75
75
driver - the webdriver object (required)
76
76
text - the text string to search for
77
- selector - the locator that is used (required)
78
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
77
+ selector - the locator for identifying the page element (required)
78
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
79
79
@Returns
80
80
Boolean (is text visible)
81
81
"""
@@ -91,8 +91,8 @@ def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
91
91
Fires the hover event for the specified element by the given selector.
92
92
@Params
93
93
driver - the webdriver object (required)
94
- selector - the locator (css selector) that is used (required)
95
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
94
+ selector - the locator for identifying the page element (required)
95
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
96
96
"""
97
97
element = driver .find_element (by = by , value = selector )
98
98
hover = ActionChains (driver ).move_to_element (element )
@@ -117,8 +117,8 @@ def hover_and_click(driver, hover_selector, click_selector,
117
117
driver - the webdriver object (required)
118
118
hover_selector - the css selector to hover over (required)
119
119
click_selector - the css selector to click on (required)
120
- hover_by - the method to search by (Default: By.CSS_SELECTOR)
121
- click_by - the method to search by (Default: By.CSS_SELECTOR)
120
+ hover_by - the hover selector type to search by (Default: By.CSS_SELECTOR)
121
+ click_by - the click selector type to search by (Default: By.CSS_SELECTOR)
122
122
timeout - number of seconds to wait for click element to appear after hover
123
123
"""
124
124
start_ms = time .time () * 1000.0
@@ -200,13 +200,12 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
200
200
specified timeout.
201
201
@Params
202
202
driver - the webdriver object
203
- selector - the locator that is used (required)
204
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
203
+ selector - the locator for identifying the page element (required)
204
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
205
205
timeout - the time to wait for elements in seconds
206
206
@Returns
207
207
A web element object
208
208
"""
209
-
210
209
element = None
211
210
start_ms = time .time () * 1000.0
212
211
stop_ms = start_ms + (timeout * 1000.0 )
@@ -234,14 +233,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
234
233
specified timeout.
235
234
@Params
236
235
driver - the webdriver object (required)
237
- selector - the locator that is used (required)
238
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
236
+ selector - the locator for identifying the page element (required)
237
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
239
238
timeout - the time to wait for elements in seconds
240
239
241
240
@Returns
242
241
A web element object
243
242
"""
244
-
245
243
element = None
246
244
start_ms = time .time () * 1000.0
247
245
stop_ms = start_ms + (timeout * 1000.0 )
@@ -281,13 +279,12 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
281
279
@Params
282
280
driver - the webdriver object (required)
283
281
text - the text that is being searched for in the element (required)
284
- selector - the locator that is used (required)
285
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
282
+ selector - the locator for identifying the page element (required)
283
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
286
284
timeout - the time to wait for elements in seconds
287
285
@Returns
288
286
A web element object that contains the text searched for
289
287
"""
290
-
291
288
element = None
292
289
start_ms = time .time () * 1000.0
293
290
stop_ms = start_ms + (timeout * 1000.0 )
@@ -324,13 +321,12 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
324
321
@Params
325
322
driver - the webdriver object (required)
326
323
text - the exact text that is expected for the element (required)
327
- selector - the locator that is used (required)
328
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
324
+ selector - the locator for identifying the page element (required)
325
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
329
326
timeout - the time to wait for elements in seconds
330
327
@Returns
331
328
A web element object that contains the text searched for
332
329
"""
333
-
334
330
element = None
335
331
start_ms = time .time () * 1000.0
336
332
stop_ms = start_ms + (timeout * 1000.0 )
@@ -364,11 +360,10 @@ def wait_for_element_absent(driver, selector, by=By.CSS_SELECTOR,
364
360
specified timeout.
365
361
@Params
366
362
driver - the webdriver object
367
- selector - the locator that is used (required)
368
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
363
+ selector - the locator for identifying the page element (required)
364
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
369
365
timeout - the time to wait for elements in seconds
370
366
"""
371
-
372
367
start_ms = time .time () * 1000.0
373
368
stop_ms = start_ms + (timeout * 1000.0 )
374
369
for x in range (int (timeout * 10 )):
@@ -395,11 +390,10 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
395
390
specified timeout.
396
391
@Params
397
392
driver - the webdriver object (required)
398
- selector - the locator that is used (required)
399
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
393
+ selector - the locator for identifying the page element (required)
394
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
400
395
timeout - the time to wait for the element in seconds
401
396
"""
402
-
403
397
start_ms = time .time () * 1000.0
404
398
stop_ms = start_ms + (timeout * 1000.0 )
405
399
for x in range (int (timeout * 10 )):
@@ -422,14 +416,45 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
422
416
selector , timeout , plural ))
423
417
424
418
419
+ def wait_for_text_not_visible (driver , text , selector , by = By .CSS_SELECTOR ,
420
+ timeout = settings .LARGE_TIMEOUT ):
421
+ """
422
+ Searches for the text in the element of the given selector on the page.
423
+ Returns True if the text is not visible on the page within the timeout.
424
+ Raises an exception if the text is still present after the timeout.
425
+ @Params
426
+ driver - the webdriver object (required)
427
+ text - the text that is being searched for in the element (required)
428
+ selector - the locator for identifying the page element (required)
429
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
430
+ timeout - the time to wait for elements in seconds
431
+ @Returns
432
+ A web element object that contains the text searched for
433
+ """
434
+ start_ms = time .time () * 1000.0
435
+ stop_ms = start_ms + (timeout * 1000.0 )
436
+ for x in range (int (timeout * 10 )):
437
+ if not is_text_visible (driver , text , selector , by = by ):
438
+ return True
439
+ now_ms = time .time () * 1000.0
440
+ if now_ms >= stop_ms :
441
+ break
442
+ time .sleep (0.1 )
443
+ plural = "s"
444
+ if timeout == 1 :
445
+ plural = ""
446
+ raise Exception ("Text {%s} in {%s} was still visible after %s "
447
+ "second%s!" % (text , selector , timeout , plural ))
448
+
449
+
425
450
def find_visible_elements (driver , selector , by = By .CSS_SELECTOR ):
426
451
"""
427
452
Finds all WebElements that match a selector and are visible.
428
453
Similar to webdriver.find_elements.
429
454
@Params
430
455
driver - the webdriver object (required)
431
- selector - the locator that is used to search the DOM (required)
432
- by - the method to search for the locator (Default: By.CSS_SELECTOR)
456
+ selector - the locator for identifying the page element (required)
457
+ by - the type of selector being used (Default: By.CSS_SELECTOR)
433
458
"""
434
459
elements = driver .find_elements (by = by , value = selector )
435
460
return [element for element in elements if element .is_displayed ()]
@@ -534,7 +559,6 @@ def wait_for_and_switch_to_alert(driver, timeout=settings.LARGE_TIMEOUT):
534
559
driver - the webdriver object (required)
535
560
timeout - the time to wait for the alert in seconds
536
561
"""
537
-
538
562
start_ms = time .time () * 1000.0
539
563
stop_ms = start_ms + (timeout * 1000.0 )
540
564
for x in range (int (timeout * 10 )):
@@ -560,7 +584,6 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
560
584
frame - the frame element, name, or index
561
585
timeout - the time to wait for the alert in seconds
562
586
"""
563
-
564
587
start_ms = time .time () * 1000.0
565
588
stop_ms = start_ms + (timeout * 1000.0 )
566
589
for x in range (int (timeout * 10 )):
@@ -584,7 +607,6 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
584
607
window - the window index or window handle
585
608
timeout - the time to wait for the window in seconds
586
609
"""
587
-
588
610
start_ms = time .time () * 1000.0
589
611
stop_ms = start_ms + (timeout * 1000.0 )
590
612
if isinstance (window , int ):
0 commit comments