@@ -288,7 +288,7 @@ def find_elements_by_text(self, text, tag_name=None):
288288 return updated_elements
289289
290290 def select (self , selector , timeout = None ):
291- """Similar to find_element(), but without text-based search ."""
291+ """Similar to find_element()."""
292292 if not timeout :
293293 timeout = settings .SMALL_TIMEOUT
294294 self .__add_light_pause ()
@@ -297,12 +297,25 @@ def select(self, selector, timeout=None):
297297 tag_name = selector .split (":contains(" )[0 ].split (" " )[- 1 ]
298298 text = selector .split (":contains(" )[1 ].split (")" )[0 ][1 :- 1 ]
299299 with suppress (Exception ):
300+ new_timeout = timeout
301+ if new_timeout < 1 :
302+ new_timeout = 1
300303 self .loop .run_until_complete (
301- self .page .select (tag_name , timeout = 5 )
304+ self .page .select (tag_name , timeout = new_timeout )
302305 )
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
306319 failure = False
307320 try :
308321 element = self .loop .run_until_complete (
@@ -313,11 +326,8 @@ def select(self, selector, timeout=None):
313326 plural = "s"
314327 if timeout == 1 :
315328 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 )
321331 if failure :
322332 raise Exception (message )
323333 element = self .__add_sync_methods (element )
0 commit comments