Beispiel #1
0
        /// <summary>
        /// Waits for a selector to be added to the DOM
        /// </summary>
        /// <param name="xpath">A xpath selector of an element to wait for</param>
        /// <param name="options">Optional waiting parameters</param>
        /// <returns>A task which resolves when element specified by xpath string is added to DOM.
        /// Resolves to `null` if waiting for `hidden: true` and xpath is not found in DOM.</returns>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// var browser = await Puppeteer.LaunchAsync(new LaunchOptions());
        /// var page = await browser.NewPageAsync();
        /// string currentURL = null;
        /// page.MainFrame
        ///     .WaitForXPathAsync("//img")
        ///     .ContinueWith(_ => Console.WriteLine("First URL with image: " + currentURL));
        /// foreach (var current in new[] { "https://example.com", "https://google.com", "https://bbc.com" })
        /// {
        ///     currentURL = current;
        ///     await page.GoToAsync(currentURL);
        /// }
        /// await browser.CloseAsync();
        /// ]]>
        /// </code>
        /// </example>
        /// <seealso cref="WaitForSelectorAsync(string, WaitForSelectorOptions)"/>
        /// <seealso cref="Page.WaitForXPathAsync(string, WaitForSelectorOptions)"/>
        /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>
        public async Task <ElementHandle> WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null)
        {
            var handle = await SecondaryWorld.WaitForXPathAsync(xpath, 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);
        }