MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / wait

Method wait

javascript/selenium-webdriver/lib/webdriver.js:857–964  ·  view source on GitHub ↗

@override

(condition, timeout = 0, message = undefined, pollTimeout = 200)

Source from the content-addressed store, hash-verified

855
856 /** @override */
857 wait(condition, timeout = 0, message = undefined, pollTimeout = 200) {
858 if (typeof timeout !== 'number' || timeout < 0) {
859 throw TypeError('timeout must be a number >= 0: ' + timeout)
860 }
861
862 if (typeof pollTimeout !== 'number' || pollTimeout < 0) {
863 throw TypeError('pollTimeout must be a number >= 0: ' + pollTimeout)
864 }
865
866 if (promise.isPromise(condition)) {
867 return new Promise((resolve, reject) => {
868 if (!timeout) {
869 resolve(condition)
870 return
871 }
872
873 let start = Date.now()
874 let timer = setTimeout(function () {
875 timer = null
876 try {
877 let timeoutMessage = resolveWaitMessage(message)
878 reject(
879 new error.TimeoutError(
880 `${timeoutMessage}Timed out waiting for promise to resolve after ${Date.now() - start}ms`,
881 ),
882 )
883 } catch (ex) {
884 reject(
885 new error.TimeoutError(
886 `${ex.message}\nTimed out waiting for promise to resolve after ${Date.now() - start}ms`,
887 ),
888 )
889 }
890 }, timeout)
891 const clearTimer = () => timer && clearTimeout(timer)
892
893 /** @type {!IThenable} */ condition.then(
894 function (value) {
895 clearTimer()
896 resolve(value)
897 },
898 function (error) {
899 clearTimer()
900 reject(error)
901 },
902 )
903 })
904 }
905
906 let fn = /** @type {!Function} */ (condition)
907 if (condition instanceof Condition) {
908 message = message || condition.description()
909 fn = condition.fn
910 }
911
912 if (typeof fn !== 'function') {
913 throw TypeError('Wait condition must be a promise-like object, function, or a ' + 'Condition object')
914 }

Callers 15

headless.jsFile · 0.45
google_search.jsFile · 0.45
logging.jsFile · 0.45
chrome_android.jsFile · 0.45
window_test.jsFile · 0.45
changeSizeByFunction · 0.45
devtools_test.jsFile · 0.45

Calls 6

resolveWaitMessageFunction · 0.85
rejectFunction · 0.85
nowMethod · 0.80
callMethod · 0.65
resolveFunction · 0.50
descriptionMethod · 0.45