@@ -217,9 +217,9 @@ def wait_for_element_present(driver, selector, by=By.CSS_SELECTOR,
217
217
timeout = settings .LARGE_TIMEOUT ):
218
218
"""
219
219
Searches for the specified element by the given selector. Returns the
220
- element object if the element is present on the page. The element can be
221
- invisible. Raises an exception if the element does not appear in the
222
- specified timeout.
220
+ element object if it exists in the HTML. ( The element can be invisible.)
221
+ Raises NoSuchElementException if the element does not exist in the HTML
222
+ within the specified timeout.
223
223
@Params
224
224
driver - the webdriver object
225
225
selector - the locator for identifying the page element (required)
@@ -256,24 +256,27 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
256
256
"""
257
257
Searches for the specified element by the given selector. Returns the
258
258
element object if the element is present and visible on the page.
259
- Raises an exception if the element does not appear in the
260
- specified timeout.
259
+ Raises NoSuchElementException if the element does not exist in the HTML
260
+ within the specified timeout.
261
+ Raises ElementNotVisibleException if the element exists in the HTML,
262
+ but is not visible (eg. opacity is "0") within the specified timeout.
261
263
@Params
262
264
driver - the webdriver object (required)
263
265
selector - the locator for identifying the page element (required)
264
266
by - the type of selector being used (Default: By.CSS_SELECTOR)
265
267
timeout - the time to wait for elements in seconds
266
-
267
268
@Returns
268
269
A web element object
269
270
"""
270
271
element = None
272
+ is_present = False
271
273
start_ms = time .time () * 1000.0
272
274
stop_ms = start_ms + (timeout * 1000.0 )
273
275
for x in range (int (timeout * 10 )):
274
276
s_utils .check_if_time_limit_exceeded ()
275
277
try :
276
278
element = driver .find_element (by = by , value = selector )
279
+ is_present = True
277
280
if element .is_displayed ():
278
281
return element
279
282
else :
@@ -288,6 +291,13 @@ def wait_for_element_visible(driver, selector, by=By.CSS_SELECTOR,
288
291
if timeout == 1 :
289
292
plural = ""
290
293
if not element and by != By .LINK_TEXT :
294
+ if not is_present :
295
+ # The element does not exist in the HTML
296
+ message = (
297
+ "Element {%s} was not present after %s second%s!"
298
+ "" % (selector , timeout , plural ))
299
+ timeout_exception (NoSuchElementException , message )
300
+ # The element exists in the HTML, but is not visible
291
301
message = (
292
302
"Element {%s} was not visible after %s second%s!"
293
303
"" % (selector , timeout , plural ))
@@ -304,8 +314,11 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
304
314
"""
305
315
Searches for the specified element by the given selector. Returns the
306
316
element object if the text is present in the element and visible
307
- on the page. Raises an exception if the text or element do not appear
308
- in the specified timeout.
317
+ on the page.
318
+ Raises NoSuchElementException if the element does not exist in the HTML
319
+ within the specified timeout.
320
+ Raises ElementNotVisibleException if the element exists in the HTML,
321
+ but the text is not visible within the specified timeout.
309
322
@Params
310
323
driver - the webdriver object (required)
311
324
text - the text that is being searched for in the element (required)
@@ -316,12 +329,14 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
316
329
A web element object that contains the text searched for
317
330
"""
318
331
element = None
332
+ is_present = False
319
333
start_ms = time .time () * 1000.0
320
334
stop_ms = start_ms + (timeout * 1000.0 )
321
335
for x in range (int (timeout * 10 )):
322
336
s_utils .check_if_time_limit_exceeded ()
323
337
try :
324
338
element = driver .find_element (by = by , value = selector )
339
+ is_present = True
325
340
if element .is_displayed () and text in element .text :
326
341
return element
327
342
else :
@@ -336,6 +351,13 @@ def wait_for_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
336
351
if timeout == 1 :
337
352
plural = ""
338
353
if not element :
354
+ if not is_present :
355
+ # The element does not exist in the HTML
356
+ message = (
357
+ "Element {%s} was not present after %s second%s!"
358
+ "" % (selector , timeout , plural ))
359
+ timeout_exception (NoSuchElementException , message )
360
+ # The element exists in the HTML, but the text is not visible
339
361
message = (
340
362
"Expected text {%s} for {%s} was not visible after %s second%s!"
341
363
"" % (text , selector , timeout , plural ))
@@ -348,8 +370,10 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
348
370
Searches for the specified element by the given selector. Returns the
349
371
element object if the text matches exactly with the text in the element,
350
372
and the text is visible.
351
- Raises an exception if the text or element do not appear
352
- in the specified timeout.
373
+ Raises NoSuchElementException if the element does not exist in the HTML
374
+ within the specified timeout.
375
+ Raises ElementNotVisibleException if the element exists in the HTML,
376
+ but the exact text is not visible within the specified timeout.
353
377
@Params
354
378
driver - the webdriver object (required)
355
379
text - the exact text that is expected for the element (required)
@@ -360,12 +384,14 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
360
384
A web element object that contains the text searched for
361
385
"""
362
386
element = None
387
+ is_present = False
363
388
start_ms = time .time () * 1000.0
364
389
stop_ms = start_ms + (timeout * 1000.0 )
365
390
for x in range (int (timeout * 10 )):
366
391
s_utils .check_if_time_limit_exceeded ()
367
392
try :
368
393
element = driver .find_element (by = by , value = selector )
394
+ is_present = True
369
395
if element .is_displayed () and text .strip () == element .text .strip ():
370
396
return element
371
397
else :
@@ -380,6 +406,13 @@ def wait_for_exact_text_visible(driver, text, selector, by=By.CSS_SELECTOR,
380
406
if timeout == 1 :
381
407
plural = ""
382
408
if not element :
409
+ if not is_present :
410
+ # The element does not exist in the HTML
411
+ message = (
412
+ "Element {%s} was not present after %s second%s!"
413
+ "" % (selector , timeout , plural ))
414
+ timeout_exception (NoSuchElementException , message )
415
+ # The element exists in the HTML, but the exact text is not visible
383
416
message = (
384
417
"Expected exact text {%s} for {%s} was not visible "
385
418
"after %s second%s!" % (text , selector , timeout , plural ))
0 commit comments