@@ -288,7 +288,7 @@ def find_elements_by_text(self, text, tag_name=None):
288
288
return updated_elements
289
289
290
290
def select (self , selector , timeout = None ):
291
- """Similar to find_element(), but without text-based search ."""
291
+ """Similar to find_element()."""
292
292
if not timeout :
293
293
timeout = settings .SMALL_TIMEOUT
294
294
self .__add_light_pause ()
@@ -297,12 +297,25 @@ def select(self, selector, timeout=None):
297
297
tag_name = selector .split (":contains(" )[0 ].split (" " )[- 1 ]
298
298
text = selector .split (":contains(" )[1 ].split (")" )[0 ][1 :- 1 ]
299
299
with suppress (Exception ):
300
+ new_timeout = timeout
301
+ if new_timeout < 1 :
302
+ new_timeout = 1
300
303
self .loop .run_until_complete (
301
- self .page .select (tag_name , timeout = 5 )
304
+ self .page .select (tag_name , timeout = new_timeout )
302
305
)
303
- self .loop .run_until_complete (self .page .find (text , timeout = 5 ))
304
- element = self .find_elements_by_text (text , tag_name = tag_name )[0 ]
305
- return self .__add_sync_methods (element )
306
+ self .loop .run_until_complete (
307
+ self .page .find (text , timeout = new_timeout )
308
+ )
309
+ elements = self .find_elements_by_text (text , tag_name = tag_name )
310
+ if not elements :
311
+ plural = "s"
312
+ if timeout == 1 :
313
+ plural = ""
314
+ msg = "\n Element {%s} was not found after %s second%s!"
315
+ message = msg % (selector , timeout , plural )
316
+ raise Exception (message )
317
+ element = self .__add_sync_methods (elements [0 ])
318
+ return element
306
319
failure = False
307
320
try :
308
321
element = self .loop .run_until_complete (
@@ -313,11 +326,8 @@ def select(self, selector, timeout=None):
313
326
plural = "s"
314
327
if timeout == 1 :
315
328
plural = ""
316
- message = "\n Element {%s} was not found after %s second%s!" % (
317
- selector ,
318
- timeout ,
319
- plural ,
320
- )
329
+ msg = "\n Element {%s} was not found after %s second%s!"
330
+ message = msg % (selector , timeout , plural )
321
331
if failure :
322
332
raise Exception (message )
323
333
element = self .__add_sync_methods (element )
0 commit comments