Example #1
0
        /// <summary>
        /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandle"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arrayHandle">An <see cref="JSHandle"/> that represents an array of <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>
        /// <param name="pageFunction">Function to be evaluated in browser context</param>
        /// <param name="args">Arguments to pass to <c>pageFunction</c></param>
        /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>
        public static async Task <T> EvaluateFunctionAsync <T>(this JSHandle arrayHandle, string pageFunction, params object[] args)
        {
            var result = await arrayHandle.EvaluateFunctionAsync <T>(pageFunction, args).ConfigureAwait(false);

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

            return(result);
        }
Example #2
0
        /// <summary>
        /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandle"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>
        /// </summary>
        /// <typeparam name="T">The type to deserialize the result to</typeparam>
        /// <param name="arrayHandle">An <see cref="JSHandle"/> that represents an array of <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>
        /// <param name="pageFunction">Function to be evaluated in browser context</param>
        /// <param name="args">Arguments to pass to <c>pageFunction</c></param>
        /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>
        public static async Task <T> EvaluateFunctionAsync <T>(this JSHandle arrayHandle, string pageFunction, params object[] args)
        {
            if (arrayHandle == null)
            {
                throw new ArgumentNullException(nameof(arrayHandle));
            }

            var result = await arrayHandle.EvaluateFunctionAsync <T>(pageFunction, args).ConfigureAwait(false);

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

            return(result);
        }