How to use EvaluateFunctionAsync method of PuppeteerSharp.JSHandle class

Best Puppeteer-sharp code snippet using PuppeteerSharp.JSHandle.EvaluateFunctionAsync

ExecutionContext.cs

Source:ExecutionContext.cs Github

copy

Full Screen

...43 /// <param name="script">Script to be evaluated in browser context</param>44 /// <remarks>45 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.46 /// </remarks>47 /// <seealso cref="EvaluateFunctionAsync{T}(string, object[])"/>48 /// <seealso cref="EvaluateExpressionHandleAsync(string)"/>49 /// <returns>Task which resolves to script return value</returns>50 public Task<JToken> EvaluateExpressionAsync(string script) => EvaluateExpressionAsync<JToken>(script);51 /// <summary>52 /// Executes a script in browser context53 /// </summary>54 /// <typeparam name="T">The type to deserialize the result to</typeparam>55 /// <param name="script">Script to be evaluated in browser context</param>56 /// <remarks>57 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.58 /// </remarks>59 /// <seealso cref="EvaluateFunctionAsync{T}(string, object[])"/>60 /// <seealso cref="EvaluateExpressionHandleAsync(string)"/>61 /// <returns>Task which resolves to script return value</returns>62 public Task<T> EvaluateExpressionAsync<T>(string script)63 => RemoteObjectTaskToObject<T>(EvaluateExpressionInternalAsync(true, script));64 internal async Task<JSHandle> EvaluateExpressionHandleAsync(string script)65 => CreateJSHandle(await EvaluateExpressionInternalAsync(false, script).ConfigureAwait(false));66 /// <summary>67 /// Executes a function in browser context68 /// </summary>69 /// <param name="script">Script to be evaluated in browser context</param>70 /// <param name="args">Arguments to pass to script</param>71 /// <remarks>72 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.73 /// <see cref="JSHandle"/> instances can be passed as arguments74 /// </remarks>75 /// <seealso cref="EvaluateExpressionAsync{T}(string)"/>76 /// <returns>Task which resolves to script return value</returns>77 public Task<JToken> EvaluateFunctionAsync(string script, params object[] args) => EvaluateFunctionAsync<JToken>(script, args);78 /// <summary>79 /// Executes a function in browser context80 /// </summary>81 /// <typeparam name="T">The type to deserialize the result to</typeparam>82 /// <param name="script">Script to be evaluated in browser context</param>83 /// <param name="args">Arguments to pass to script</param>84 /// <remarks>85 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.86 /// <see cref="JSHandle"/> instances can be passed as arguments87 /// </remarks>88 /// <seealso cref="EvaluateExpressionAsync{T}(string)"/>89 /// <returns>Task which resolves to script return value</returns>90 public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)91 => RemoteObjectTaskToObject<T>(EvaluateFunctionInternalAsync(true, script, args));92 internal async Task<JSHandle> EvaluateFunctionHandleAsync(string script, params object[] args)93 => CreateJSHandle(await EvaluateFunctionInternalAsync(false, script, args).ConfigureAwait(false));94 /// <summary>95 /// The method iterates JavaScript heap and finds all the objects with the given prototype.96 /// </summary>97 /// <returns>A task which resolves to a handle to an array of objects with this prototype.</returns>98 /// <param name="prototypeHandle">A handle to the object prototype.</param>99 public async Task<JSHandle> QueryObjectsAsync(JSHandle prototypeHandle)100 {101 if (prototypeHandle.Disposed)102 {103 throw new PuppeteerException("Prototype JSHandle is disposed!");104 }...

Full Screen

Full Screen

PageCTL.cs

Source:PageCTL.cs Github

copy

Full Screen

...120 public async Task<bool> WaitForPropertyAsync(string selector, string property, object value, int timeout = 30000)121 {122 do123 {124 bool success = await mPage.EvaluateFunctionAsync<bool>(@"125 (selector, property, value) => {126 const ele = document.querySelector(selector);127 if (ele == null) return false;128 return ele[property] == value;129 }", selector, property, value);130 if (success)131 {132 return true;133 }134 await Task.Delay(3000);135 timeout -= 3000;136 }137 while (timeout > 0);138 return false;139 }140 public async Task<bool> WaitForElementAsync(string selector, Func<ElementHandle, bool> func, int timeout = 30000)141 {142 do143 {144 ElementHandle element;145 try146 {147 element = await mPage.QuerySelectorAsync(selector);148 149 }150 catch (Exception ex)151 {152 Console.WriteLine(ex.Message);153 element = null;154 }155 if (element != null && func(element))156 {157 return true;158 }159 await Task.Delay(1000);160 timeout -= 1000;161 } while (timeout > 0);162 return false;163 }164 public async Task<bool> StopLoadingAsync()165 {166 try167 {168 await mPage.EvaluateExpressionAsync("window.stop()");169 return true;170 }171 catch172 {173 return false;174 }175 }176 public async Task<bool> SetInputValueAsync(string selector, string value)177 {178 try179 {180 await mPage.EvaluateFunctionAsync(@"181 (selector, value) => {182 const ele = document.querySelector(selector);183 if (ele != null) ele.value = value;184 }", selector, value);185 return true;186 }187 catch188 {189 return false;190 }191 }192 public async Task<string> GetInputValueAsync(string selector)193 {194 try195 {196 return await mPage.EvaluateFunctionAsync<string>(@"197 (selector) => {198 const ele = document.querySelector(selector);199 if (ele != null)200 {201 return ele.value;202 }203 else204 {205 return null;206 }207 }", selector);208 }209 catch210 {211 return null;212 }213 }214 public async Task<bool> SetElementsIDAsync(string selector, string name, int start_index = 0)215 {216 try217 {218 await mPage.EvaluateFunctionAsync(@"219 (selector, name, start_index) => {220 const eles = document.querySelectorAll(selector);221 for(var i = 0; i < eles.length; i++) {222 const ele = eles[i];223 ele.id = name.concat(start_index + i);224 }225 }", selector, name, start_index);226 return true;227 }228 catch229 {230 return false;231 }232 }233 public async Task<bool> SetChildsIDAsync(string selector, string name, int start_index = 0)234 {235 try236 {237 return await mPage.EvaluateFunctionAsync<bool>(@"238 (selector, name, start_index) => {239 const parent = document.querySelector(selector);240 if (parent == null) return false;241 const eles = parent.children;242 for(var i = 0; i < eles.length; i++) {243 const ele = eles[i];244 ele.id = name.concat(i);245 }246 return true;247 }", selector, name, start_index);248 }249 catch250 {251 return false;252 }253 }254 public async Task<string> GetElementInnerHTML(string selector)255 {256 try257 {258 ElementHandle element = await mPage.QuerySelectorAsync(selector);259 JSHandle handler = await element.GetPropertyAsync("innerHTML");260 return handler.ToString().Replace("JSHandle:", string.Empty);261 }262 catch263 {264 return null;265 }266 }267 public async Task<string> GetElementInnerText(string selector)268 {269 try270 {271 ElementHandle element = await mPage.QuerySelectorAsync(selector);272 JSHandle handler = await element.GetPropertyAsync("innerText");273 return handler.ToString().Replace("JSHandle:", string.Empty);274 }275 catch276 {277 return null;278 }279 }280 public async Task<string[]> GetElementClassListAsynct(string selector)281 {282 try283 {284 ElementHandle element = await mPage.QuerySelectorAsync(selector);285 JSHandle handler = await element.GetPropertyAsync("classList");286 Dictionary<string, string> value = await handler.JsonValueAsync<Dictionary<string, string>>();287 string[] result = new string[value.Count];288 value.Values.CopyTo(result, 0);289 return result;290 }291 catch292 {293 return null;294 }295 }296 public async Task<string> GetElementClassStringAsync(string selector)297 {298 try299 {300 ElementHandle element = await mPage.QuerySelectorAsync(selector);301 JSHandle handler = await element.GetPropertyAsync("classList");302 object value = await handler.JsonValueAsync();303 return value.ToString();304 }305 catch306 {307 return null;308 }309 }310 public async Task<string> GetURLAsync(int times = 3, int delay = 3000)311 {312 do313 {314 try315 {316 return await mPage.EvaluateFunctionAsync<string>(@"317 () => {318 return document.URL;319 }");320 }321 catch322 {323 await Task.Delay(delay);324 times--;325 }326 }327 while (times > 0);328 return mPage.Url;329 }330 }...

Full Screen

Full Screen

JSHandle.cs

Source:JSHandle.cs Github

copy

Full Screen

...169 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.170 /// <see cref="JSHandle"/> instances can be passed as arguments171 /// </remarks>172 /// <returns>Task which resolves to script return value</returns>173 public Task<JToken> EvaluateFunctionAsync(string script, params object[] args)174 {175 var list = new List<object>(args);176 list.Insert(0, this);177 return ExecutionContext.EvaluateFunctionAsync<JToken>(script, list.ToArray());178 }179 /// <summary>180 /// Executes a function in browser context181 /// </summary>182 /// <typeparam name="T">The type to deserialize the result to</typeparam>183 /// <param name="script">Script to be evaluated in browser context</param>184 /// <param name="args">Arguments to pass to script</param>185 /// <remarks>186 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.187 /// <see cref="JSHandle"/> instances can be passed as arguments188 /// </remarks>189 /// <returns>Task which resolves to script return value</returns>190 public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)191 {192 var list = new List<object>(args);193 list.Insert(0, this);194 return ExecutionContext.EvaluateFunctionAsync<T>(script, list.ToArray());195 }196 internal object FormatArgument(ExecutionContext context)197 {198 if (ExecutionContext != context)199 {200 throw new PuppeteerException("JSHandles can be evaluated only in the context they were created!");201 }202 if (Disposed)203 {204 throw new PuppeteerException("JSHandle is disposed!");205 }206 var unserializableValue = RemoteObject.UnserializableValue;207 if (unserializableValue != null)208 {...

Full Screen

Full Screen

Worker.cs

Source:Worker.cs Github

copy

Full Screen

...86 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.87 /// <see cref="JSHandle"/> instances can be passed as arguments88 /// </remarks>89 /// <returns>Task which resolves to script return value</returns>90 public async Task<JToken> EvaluateFunctionAsync(string script, params object[] args)91 => await (await ExecutionContextTask.ConfigureAwait(false)).EvaluateFunctionAsync(script, args).ConfigureAwait(false);92 /// <summary>93 /// Executes a function in the context94 /// </summary>95 /// <typeparam name="T">The type to deserialize the result to</typeparam>96 /// <param name="script">Script to be evaluated in browser context</param>97 /// <param name="args">Arguments to pass to script</param>98 /// <remarks>99 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.100 /// <see cref="JSHandle"/> instances can be passed as arguments101 /// </remarks>102 /// <returns>Task which resolves to script return value</returns>103 public async Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)104 => await (await ExecutionContextTask.ConfigureAwait(false)).EvaluateFunctionAsync<T>(script, args).ConfigureAwait(false);105 /// <summary>106 /// Executes a script in browser context107 /// </summary>108 /// <param name="script">Script to be evaluated in browser context</param>109 /// <remarks>110 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.111 /// </remarks>112 /// <returns>Task which resolves to script return value</returns>113 /// <seealso cref="ExecutionContext.EvaluateExpressionHandleAsync(string)"/>114 public async Task<JSHandle> EvaluateExpressionHandleAsync(string script)115 => await (await ExecutionContextTask.ConfigureAwait(false)).EvaluateExpressionHandleAsync(script).ConfigureAwait(false);116 internal Task<ExecutionContext> ExecutionContextTask => _executionContextCallback.Task;117 internal async void OnMessageReceived(object sender, MessageEventArgs e)118 {...

Full Screen

Full Screen

Extensions.cs

Source:Extensions.cs Github

copy

Full Screen

...13 /// <param name="pageFunction">Function to be evaluated in browser context</param>14 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>15 /// <returns>Task</returns>16 /// <exception cref="SelectorException">If <paramref name="elementHandleTask"/> resolves to <c>null</c></exception>17 public static Task EvaluateFunctionAsync(this Task<ElementHandle> elementHandleTask, string pageFunction, params object[] args)18 => elementHandleTask.EvaluateFunctionAsync<object>(pageFunction, args);19 /// <summary>20 /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="elementHandleTask"/> as the first argument21 /// </summary>22 /// <typeparam name="T">The type of the response</typeparam>23 /// <param name="elementHandleTask">A task that returns an <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>24 /// <param name="pageFunction">Function to be evaluated in browser context</param>25 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>26 /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>27 /// <exception cref="SelectorException">If <paramref name="elementHandleTask"/> resolves to <c>null</c></exception>28 public static async Task<T> EvaluateFunctionAsync<T>(this Task<ElementHandle> elementHandleTask, string pageFunction, params object[] args)29 {30 var elementHandle = await elementHandleTask.ConfigureAwait(false);31 if (elementHandle == null)32 {33 throw new SelectorException("Error: failed to find element matching selector");34 }35 return await elementHandle.EvaluateFunctionAsync<T>(pageFunction, args).ConfigureAwait(false);36 }37 /// <summary>38 /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome the <paramref name="elementHandle"/> as the first argument39 /// </summary>40 /// <typeparam name="T">The type of the response</typeparam>41 /// <param name="elementHandle">An <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>42 /// <param name="pageFunction">Function to be evaluated in browser context</param>43 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>44 /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>45 /// <exception cref="SelectorException">If <paramref name="elementHandle"/> is <c>null</c></exception>46 public static async Task<T> EvaluateFunctionAsync<T>(this ElementHandle elementHandle, string pageFunction, params object[] args)47 {48 if (elementHandle == null)49 {50 throw new SelectorException("Error: failed to find element matching selector");51 }52 var newArgs = new object[args.Length + 1];53 newArgs[0] = elementHandle;54 args.CopyTo(newArgs, 1);55 var result = await elementHandle.ExecutionContext.EvaluateFunctionAsync<T>(pageFunction, newArgs).ConfigureAwait(false);56 await elementHandle.DisposeAsync().ConfigureAwait(false);57 return result;58 }59 /// <summary>60 /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandleTask"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>61 /// </summary>62 /// <param name="arrayHandleTask">A task that returns 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>63 /// <param name="pageFunction">Function to be evaluated in browser context</param>64 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>65 /// <returns>Task</returns>66 public static Task EvaluateFunctionAsync(this Task<JSHandle> arrayHandleTask, string pageFunction, params object[] args)67 => arrayHandleTask.EvaluateFunctionAsync<object>(pageFunction, args);68 /// <summary>69 /// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandleTask"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>70 /// </summary>71 /// <typeparam name="T"></typeparam>72 /// <param name="arrayHandleTask">A task that returns 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>73 /// <param name="pageFunction">Function to be evaluated in browser context</param>74 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>75 /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>76 public static async Task<T> EvaluateFunctionAsync<T>(this Task<JSHandle> arrayHandleTask, string pageFunction, params object[] args)77 => await (await arrayHandleTask.ConfigureAwait(false)).EvaluateFunctionAsync<T>(pageFunction, args).ConfigureAwait(false);78 /// <summary>79 /// 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)"/>80 /// </summary>81 /// <typeparam name="T"></typeparam>82 /// <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>83 /// <param name="pageFunction">Function to be evaluated in browser context</param>84 /// <param name="args">Arguments to pass to <c>pageFunction</c></param>85 /// <returns>Task which resolves to the return value of <c>pageFunction</c></returns>86 public static async Task<T> EvaluateFunctionAsync<T>(this JSHandle arrayHandle, string pageFunction, params object[] args)87 {88 var response = await arrayHandle.JsonValueAsync<object[]>().ConfigureAwait(false);89 var newArgs = new object[args.Length + 1];90 newArgs[0] = arrayHandle;91 args.CopyTo(newArgs, 1);92 var result = await arrayHandle.ExecutionContext.EvaluateFunctionAsync<T>(pageFunction, newArgs).ConfigureAwait(false);93 await arrayHandle.DisposeAsync().ConfigureAwait(false);94 return result;95 }96 }97}...

Full Screen

Full Screen

BookReSellService.cs

Source:BookReSellService.cs Github

copy

Full Screen

...142 foreach (var element in elementHandles)143 {144 //var jsHandle = await element.GetPropertyAsync("dataset");145 //var price = await element.GetPropertyAsync("dataset.price");146 var price = decimal.Parse(await element.EvaluateFunctionAsync<string>("(el) => el.getAttribute(\"data-price\")", element));147 var vendorId = await element.EvaluateFunctionAsync<string>("(el) => el.getAttribute(\"data-vendorid\")", element);148 var vendorName = await element.EvaluateFunctionAsync<string>("(el) => el.getAttribute(\"data-vendor\")", element);149 VendorResult result = new VendorResult(book, vendorId, vendorName, price);150 //Console.WriteLine(result.ToString());151 vendorResults.Add(result);152 }153 }154 static string TrimElementHandlerPropertyString(string elementHandlerPropertyString) => elementHandlerPropertyString.Substring(9);155 static string TrimElementHandlerPropertyString(JSHandle elementHandlerPropertyString) => elementHandlerPropertyString.ToString().Substring(9);156 }157}...

Full Screen

Full Screen

PageEvaluateHandle.cs

Source:PageEvaluateHandle.cs Github

copy

Full Screen

...19 [PuppeteerFact]20 public async Task ShouldAcceptObjectHandleAsAnArgument()21 {22 var navigatorHandle = await Page.EvaluateFunctionHandleAsync("() => navigator");23 var text = await Page.EvaluateFunctionAsync<string>(24 "(e) => e.userAgent",25 navigatorHandle);26 Assert.Contains("Mozilla", text);27 }28 [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should accept object handle to primitive types")]29 [PuppeteerFact]30 public async Task ShouldAcceptObjectHandleToPrimitiveTypes()31 {32 var aHandle = await Page.EvaluateFunctionHandleAsync("() => 5");33 var isFive = await Page.EvaluateFunctionAsync<bool>(34 "(e) => Object.is(e, 5)",35 aHandle);36 Assert.True(isFive);37 }38 [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should warn on nested object handles")]39 [PuppeteerFact]40 public async Task ShouldWarnOnNestedObjectHandles()41 {42 var aHandle = await Page.EvaluateFunctionHandleAsync("() => document.body");43 var exception = await Assert.ThrowsAsync<EvaluationFailedException>(() =>44 Page.EvaluateFunctionHandleAsync("(opts) => opts.elem.querySelector('p')", new { aHandle }));45 Assert.Contains("Are you passing a nested JSHandle?", exception.Message);46 }47 [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should accept object handle to unserializable value")]48 [PuppeteerFact]49 public async Task ShouldAcceptObjectHandleToUnserializableValue()50 {51 var aHandle = await Page.EvaluateFunctionHandleAsync("() => Infinity");52 Assert.True(await Page.EvaluateFunctionAsync<bool>(53 "(e) => Object.is(e, Infinity)",54 aHandle));55 }56 [PuppeteerTest("jshandle.spec.ts", "Page.evaluateHandle", "should use the same JS wrappers")]57 [PuppeteerFact]58 public async Task ShouldUseTheSameJSWrappers()59 {60 var aHandle = await Page.EvaluateFunctionHandleAsync(@"() => {61 globalThis.FOO = 123;62 return window;63 }");64 Assert.Equal(123, await Page.EvaluateFunctionAsync<int>(65 "(e) => e.FOO",66 aHandle));67 }68 }69}...

Full Screen

Full Screen

QueryObjectsTests.cs

Source:QueryObjectsTests.cs Github

copy

Full Screen

...15 // Instantiate an object16 await Page.EvaluateExpressionAsync("window.set = new Set(['hello', 'world'])");17 var prototypeHandle = await Page.EvaluateExpressionHandleAsync("Set.prototype");18 var objectsHandle = await Page.QueryObjectsAsync(prototypeHandle);19 var count = await Page.EvaluateFunctionAsync<int>("objects => objects.length", objectsHandle);20 Assert.Equal(1, count);21 var values = await Page.EvaluateFunctionAsync<string[]>("objects => Array.from(objects[0].values())", objectsHandle);22 Assert.Equal(new[] { "hello", "world" }, values);23 }24 [Fact]25 public async Task ShouldFailForDisposedHandles()26 {27 var prototypeHandle = await Page.EvaluateExpressionHandleAsync("HTMLBodyElement.prototype");28 await prototypeHandle.DisposeAsync();29 var exception = await Assert.ThrowsAsync<PuppeteerException>(()30 => Page.QueryObjectsAsync(prototypeHandle));31 Assert.Equal("Prototype JSHandle is disposed!", exception.Message);32 }33 [Fact]34 public async Task ShouldFailPrimitiveValuesAsPrototypes()35 {...

Full Screen

Full Screen

EvaluateFunctionAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions10 {11 });12 var page = await browser.NewPageAsync();13 var searchBox = await page.QuerySelectorAsync("input[title='Search']");14 await searchBox.TypeAsync("PuppeteerSharp");15 var searchButton = await page.QuerySelectorAsync("input[value='Google Search']");16 await searchButton.ClickAsync();17 var result = await page.EvaluateFunctionAsync<int>("() => document.querySelectorAll('div.g').length");18 Console.WriteLine(result);19 await browser.CloseAsync();20 }21 }22}

Full Screen

Full Screen

EvaluateFunctionAsync

Using AI Code Generation

copy

Full Screen

1using System.Threading.Tasks;2using PuppeteerSharp;3{4 {5 static async Task Main(string[] args)6 {7 var options = new LaunchOptions { Headless = true };8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 using (var browser = await Puppeteer.LaunchAsync(options))10 using (var page = await browser.NewPageAsync())11 {12 var result = await page.EvaluateFunctionAsync<int>("(a, b) => a + b", 1, 2);13 }14 }15 }16}17using System.Threading.Tasks;18using PuppeteerSharp;19{20 {21 static async Task Main(string[] args)22 {23 var options = new LaunchOptions { Headless = true };24 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);25 using (var browser = await Puppeteer.LaunchAsync(options))26 using (var page = await browser.NewPageAsync())27 {28 var result = await page.EvaluateFunctionHandleAsync("() => document.body");29 }30 }31 }32}33using System.Threading.Tasks;34using PuppeteerSharp;35{36 {37 static async Task Main(string[] args)38 {39 var options = new LaunchOptions { Headless = true };40 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);41 using (var browser = await Puppeteer.LaunchAsync(options))42 using (var page = await browser.NewPageAsync())43 {44 var result = await page.EvaluateFunctionHandleAsync("() => document.body");45 }46 }47 }48}

Full Screen

Full Screen

EvaluateFunctionAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });10 var page = await browser.NewPageAsync();11 var element = await page.QuerySelectorAsync("input[name='q']");12 var result = await element.EvaluateFunctionAsync("x => x.value");13 Console.WriteLine(result);14 await browser.CloseAsync();15 }16 }17}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful