Beispiel #1
0
        /// <summary>
        /// Waits for a selector to be added to the DOM
        /// </summary>
        /// <param name="selector">A selector of an element to wait for</param>
        /// <param name="options">Optional waiting parameters</param>
        /// <returns>A task that resolves when element specified by selector string is added to DOM.
        /// Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM.</returns>
        /// <seealso cref="WaitForXPathAsync(string, WaitForSelectorOptions)"/>
        /// <seealso cref="Page.WaitForSelectorAsync(string, WaitForSelectorOptions)"/>
        /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>
        public async Task <ElementHandle> WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null)
        {
            var handle = await SecondaryWorld.WaitForSelectorAsync(selector, options).ConfigureAwait(false);

            if (handle == null)
            {
                return(null);
            }
            var mainExecutionContext = await MainWorld.GetExecutionContextAsync().ConfigureAwait(false);

            var result = await mainExecutionContext.AdoptElementHandleASync(handle).ConfigureAwait(false);

            await handle.DisposeAsync().ConfigureAwait(false);

            return(result);
        }