@@ -48,20 +48,29 @@ def __init__(
4848 ):
4949 """Constructor, takes a WebDriver instance and timeout in seconds.
5050
51- :Args:
52- - driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement
53- - timeout - Number of seconds before timing out
54- - poll_frequency - sleep interval between calls
55- By default, it is 0.5 second.
56- - ignored_exceptions - iterable structure of exception classes ignored during calls.
57- By default, it contains NoSuchElementException only.
58-
59- Example::
60-
61- from selenium.webdriver.support.wait import WebDriverWait \n
62- element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "someId")) \n
63- is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\\ \n
64- until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
51+ Parameters:
52+ ----------
53+ driver
54+ - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement
55+ timeout
56+ - Number of seconds before timing out
57+ poll_frequency
58+ - Sleep interval between calls
59+ - By default, it is 0.5 second.
60+ ignored_exceptions
61+ - Iterable structure of exception classes ignored during calls.
62+ - By default, it contains NoSuchElementException only.
63+
64+ Example:
65+ --------
66+ >>> from selenium.webdriver.common.by import By
67+ >>> from selenium.webdriver.support.wait import WebDriverWait
68+ >>> from selenium.common.exceptions import ElementNotVisibleException
69+ >>>
70+ >>> # Wait until the element is no longer visible
71+ >>> is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).until_not(
72+ ... lambda x: x.find_element(By.ID, "someId").is_displayed()
73+ ... )
6574 """
6675 self ._driver = driver
6776 self ._timeout = float (timeout )
@@ -81,13 +90,38 @@ def __repr__(self):
8190 return f'<{ type (self ).__module__ } .{ type (self ).__name__ } (session="{ self ._driver .session_id } ")>'
8291
8392 def until (self , method : Callable [[D ], Union [Literal [False ], T ]], message : str = "" ) -> T :
84- """Calls the method provided with the driver as an argument until the \
93+ """Wait until the method returns a value that is not False
94+
95+ Calls the method provided with the driver as an argument until the
8596 return value does not evaluate to ``False``.
8697
87- :param method: callable(WebDriver)
88- :param message: optional message for :exc:`TimeoutException`
89- :returns: the result of the last call to `method`
90- :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
98+ Parameters:
99+ ----------
100+ method: callable(WebDriver)
101+ - A callable object that takes a WebDriver instance as an argument.
102+ message: str
103+ - Optional message for :exc:`TimeoutException`
104+
105+ Return:
106+ -------
107+ object: T
108+ - The result of the last call to `method`
109+
110+ Raises:
111+ -------
112+ TimeoutException
113+ - If 'method' does not return a truthy value within the WebDriverWait object's timeout
114+
115+ Example:
116+ --------
117+ >>> from selenium.webdriver.common.by import By
118+ >>> from selenium.webdriver.support.ui import WebDriverWait
119+ >>> from selenium.webdriver.support import expected_conditions as EC
120+
121+ # Wait until an element is visible on the page
122+ >>> wait = WebDriverWait(driver, 10)
123+ >>> element = wait.until(EC.visibility_of_element_located((By.ID, "exampleId")))
124+ >>> print(element.text)
91125 """
92126 screen = None
93127 stacktrace = None
@@ -107,14 +141,37 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
107141 raise TimeoutException (message , screen , stacktrace )
108142
109143 def until_not (self , method : Callable [[D ], T ], message : str = "" ) -> Union [T , Literal [True ]]:
110- """Calls the method provided with the driver as an argument until the \
111- return value evaluates to ``False``.
112-
113- :param method: callable(WebDriver)
114- :param message: optional message for :exc:`TimeoutException`
115- :returns: the result of the last call to `method`, or
116- ``True`` if `method` has raised one of the ignored exceptions
117- :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
144+ """Wait until the method returns a value that is not False
145+
146+ Calls the method provided with the driver as an argument until the
147+ return value does not evaluate to ``False``.
148+
149+ Parameters:
150+ ----------
151+ method: callable(WebDriver)
152+ - A callable object that takes a WebDriver instance as an argument.
153+ message: str
154+ - Optional message for :exc:`TimeoutException`
155+
156+ Return:
157+ -------
158+ object: T
159+ - The result of the last call to `method`
160+
161+ Raises:
162+ -------
163+ TimeoutException
164+ - If 'method' does not return False within the WebDriverWait object's timeout
165+
166+ Example:
167+ --------
168+ >>> from selenium.webdriver.common.by import By
169+ >>> from selenium.webdriver.support.ui import WebDriverWait
170+ >>> from selenium.webdriver.support import expected_conditions as EC
171+
172+ # Wait until an element is visible on the page
173+ >>> wait = WebDriverWait(driver, 10)
174+ >>> is_disappeared = wait.until_not(EC.visibility_of_element_located((By.ID, "exampleId")))
118175 """
119176 end_time = time .monotonic () + self ._timeout
120177 while True :
0 commit comments