File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,38 @@ export class Wait {
160160 }
161161 }
162162
163+ /**
164+ * Waits for an element located by a CSS selector to be visible within a maximum time.
165+ *
166+ * @async
167+ * @param {string } selector - The CSS selector of the element to wait for.
168+ * @param {number } maxTime - Maximum time to wait in milliseconds.
169+ * @returns {Promise<void> } A promise that resolves when the element is found or the time times out.
170+ * @throws {Error } Throws an error if the element is not found within the specified time.
171+ */
172+ async bySelectorAndVisible ( selector , maxTime = 6000 ) {
173+ const driver = this . browser . getDriver ( ) ;
174+
175+ try {
176+ await driver . wait (
177+ webdriver . until . elementIsVisible (
178+ driver . findElement ( webdriver . By . css ( selector ) )
179+ ) ,
180+ maxTime
181+ ) ;
182+ } catch ( error ) {
183+ log . error (
184+ 'Element by selector %s was not visible in %s ms' ,
185+ selector ,
186+ maxTime
187+ ) ;
188+ log . verbose ( error ) ;
189+ throw new Error (
190+ `Element by selector ${ selector } was not visible in ${ maxTime } ms`
191+ ) ;
192+ }
193+ }
194+
163195 /**
164196 * Waits for a specified amount of time.
165197 *
You can’t perform that action at this time.
0 commit comments