1616# under the License. 
1717
1818import  time 
19+ from  typing  import  Any 
1920from  typing  import  Callable 
2021from  typing  import  Generic 
2122from  typing  import  Literal 
@@ -92,7 +93,9 @@ def __init__(
9293    def  __repr__ (self ) ->  str :
9394        return  f'<{ type (self ).__module__ } { type (self ).__name__ } { self ._driver .session_id }  
9495
95-     def  until (self , method : Callable [[D ], Union [Literal [False ], T ]], message : str  =  "" ) ->  T :
96+     def  until (
97+         self , method : Callable [[D ], Union [Literal [False ], T ]], message : Union [str , Callable [[Any ], str ]] =  "" 
98+     ) ->  T :
9699        """Wait until the method returns a value that is not False. 
97100
98101        Calls the method provided with the driver as an argument until the 
@@ -103,7 +106,7 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
103106        method: callable(WebDriver) 
104107            - A callable object that takes a WebDriver instance as an argument. 
105108
106-         message: str 
109+         message: Union[ str, Callable[[Any], str]]  
107110            - Optional message for :exc:`TimeoutException` 
108111
109112        Return: 
@@ -143,9 +146,13 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
143146            if  time .monotonic () >  end_time :
144147                break 
145148            time .sleep (self ._poll )
146-         raise  TimeoutException (message , screen , stacktrace )
147149
148-     def  until_not (self , method : Callable [[D ], T ], message : str  =  "" ) ->  Union [T , Literal [True ]]:
150+         final_msg  =  message () if  callable (message ) else  message 
151+         raise  TimeoutException (final_msg , screen , stacktrace )
152+ 
153+     def  until_not (
154+         self , method : Callable [[D ], T ], message : Union [str , Callable [[Any ], str ]] =  "" 
155+     ) ->  Union [T , Literal [True ]]:
149156        """Wait until the method returns a value that is not False. 
150157
151158        Calls the method provided with the driver as an argument until the 
@@ -156,7 +163,7 @@ def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Lit
156163        method: callable(WebDriver) 
157164            - A callable object that takes a WebDriver instance as an argument. 
158165
159-         message: str 
166+         message: Union[ str, Callable[[Any], str]]  
160167            - Optional message for :exc:`TimeoutException` 
161168
162169        Return: 
@@ -192,4 +199,5 @@ def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Lit
192199            if  time .monotonic () >  end_time :
193200                break 
194201            time .sleep (self ._poll )
195-         raise  TimeoutException (message )
202+         final_msg  =  message () if  callable (message ) else  message 
203+         raise  TimeoutException (final_msg )
0 commit comments