MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / wait

Method wait

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

@override

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

Source from the content-addressed store, hash-verified

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

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
nowMethod · 0.80
callMethod · 0.65
resolveFunction · 0.50
rejectFunction · 0.50
descriptionMethod · 0.45