@@ -39,8 +39,8 @@ def is_element_present(driver, selector, by=By.CSS_SELECTOR):
3939 Returns whether the specified element selector is present on the page.
4040 @Params
4141 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)
4444 @Returns
4545 Boolean (is element present)
4646 """
@@ -56,8 +56,8 @@ def is_element_visible(driver, selector, by=By.CSS_SELECTOR):
5656 Returns whether the specified element selector is visible on the page.
5757 @Params
5858 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)
6161 @Returns
6262 Boolean (is element visible)
6363 """
@@ -74,8 +74,8 @@ def is_text_visible(driver, text, selector, by=By.CSS_SELECTOR):
7474 @Params
7575 driver - the webdriver object (required)
7676 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)
7979 @Returns
8080 Boolean (is text visible)
8181 """
@@ -91,8 +91,8 @@ def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
9191 Fires the hover event for the specified element by the given selector.
9292 @Params
9393 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)
9696 """
9797 element = driver .find_element (by = by , value = selector )
9898 hover = ActionChains (driver ).move_to_element (element )
@@ -117,8 +117,8 @@ def hover_and_click(driver, hover_selector, click_selector,
117117 driver - the webdriver object (required)
118118 hover_selector - the css selector to hover over (required)
119119 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)
122122 timeout - number of seconds to wait for click element to appear after hover
123123 """
124124 start_ms = time .time () * 1000.0
@@ -200,13 +200,12 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
200200 specified timeout.
201201 @Params
202202 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)
205205 timeout - the time to wait for elements in seconds
206206 @Returns
207207 A web element object
208208 """
209-
210209 element = None
211210 start_ms = time .time () * 1000.0
212211 stop_ms = start_ms + (timeout * 1000.0 )
@@ -234,14 +233,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
234233 specified timeout.
235234 @Params
236235 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)
239238 timeout - the time to wait for elements in seconds
240239
241240 @Returns
242241 A web element object
243242 """
244-
245243 element = None
246244 start_ms = time .time () * 1000.0
247245 stop_ms = start_ms + (timeout * 1000.0 )
@@ -281,13 +279,12 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
281279 @Params
282280 driver - the webdriver object (required)
283281 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)
286284 timeout - the time to wait for elements in seconds
287285 @Returns
288286 A web element object that contains the text searched for
289287 """
290-
291288 element = None
292289 start_ms = time .time () * 1000.0
293290 stop_ms = start_ms + (timeout * 1000.0 )
@@ -324,13 +321,12 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
324321 @Params
325322 driver - the webdriver object (required)
326323 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)
329326 timeout - the time to wait for elements in seconds
330327 @Returns
331328 A web element object that contains the text searched for
332329 """
333-
334330 element = None
335331 start_ms = time .time () * 1000.0
336332 stop_ms = start_ms + (timeout * 1000.0 )
@@ -364,11 +360,10 @@ def wait_for_element_absent(driver, selector, by=By.CSS_SELECTOR,
364360 specified timeout.
365361 @Params
366362 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)
369365 timeout - the time to wait for elements in seconds
370366 """
371-
372367 start_ms = time .time () * 1000.0
373368 stop_ms = start_ms + (timeout * 1000.0 )
374369 for x in range (int (timeout * 10 )):
@@ -395,11 +390,10 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
395390 specified timeout.
396391 @Params
397392 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)
400395 timeout - the time to wait for the element in seconds
401396 """
402-
403397 start_ms = time .time () * 1000.0
404398 stop_ms = start_ms + (timeout * 1000.0 )
405399 for x in range (int (timeout * 10 )):
@@ -422,14 +416,45 @@ def wait_for_element_not_visible(driver, selector, by=By.CSS_SELECTOR,
422416 selector , timeout , plural ))
423417
424418
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+
425450def find_visible_elements (driver , selector , by = By .CSS_SELECTOR ):
426451 """
427452 Finds all WebElements that match a selector and are visible.
428453 Similar to webdriver.find_elements.
429454 @Params
430455 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)
433458 """
434459 elements = driver .find_elements (by = by , value = selector )
435460 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):
534559 driver - the webdriver object (required)
535560 timeout - the time to wait for the alert in seconds
536561 """
537-
538562 start_ms = time .time () * 1000.0
539563 stop_ms = start_ms + (timeout * 1000.0 )
540564 for x in range (int (timeout * 10 )):
@@ -560,7 +584,6 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
560584 frame - the frame element, name, or index
561585 timeout - the time to wait for the alert in seconds
562586 """
563-
564587 start_ms = time .time () * 1000.0
565588 stop_ms = start_ms + (timeout * 1000.0 )
566589 for x in range (int (timeout * 10 )):
@@ -584,7 +607,6 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
584607 window - the window index or window handle
585608 timeout - the time to wait for the window in seconds
586609 """
587-
588610 start_ms = time .time () * 1000.0
589611 stop_ms = start_ms + (timeout * 1000.0 )
590612 if isinstance (window , int ):
0 commit comments