Best Puppeteer-sharp code snippet using PuppeteerSharp.Frame.XPathAsync
DOMWorld.cs
Source:DOMWorld.cs  
...99            var document = await GetDocument().ConfigureAwait(false);100            var value = await document.QuerySelectorAllAsync(selector).ConfigureAwait(false);101            return value;102        }103        internal async Task<ElementHandle[]> XPathAsync(string expression)104        {105            var document = await GetDocument().ConfigureAwait(false);106            var value = await document.XPathAsync(expression).ConfigureAwait(false);107            return value;108        }109        internal Task<string> GetContentAsync() => EvaluateFunctionAsync<string>(@"() => {110                let retVal = '';111                if (document.doctype)112                    retVal = new XMLSerializer().serializeToString(document.doctype);113                if (document.documentElement)114                    retVal += document.documentElement.outerHTML;115                return retVal;116            }");117        internal async Task SetContentAsync(string html, NavigationOptions options = null)118        {119            var waitUntil = options?.WaitUntil ?? new[] { WaitUntilNavigation.Load };120            var timeout = options?.Timeout ?? _timeoutSettings.NavigationTimeout;121            // We rely upon the fact that document.open() will reset frame lifecycle with "init"122            // lifecycle event. @see https://crrev.com/608658123            await EvaluateFunctionAsync(@"html => {124                document.open();125                document.write(html);126                document.close();127            }", html).ConfigureAwait(false);128            using (var watcher = new LifecycleWatcher(_frameManager, Frame, waitUntil, timeout))129            {130                var watcherTask = await Task.WhenAny(131                    watcher.TimeoutOrTerminationTask,132                    watcher.LifecycleTask).ConfigureAwait(false);133                await watcherTask.ConfigureAwait(false);134            }135        }136        internal async Task<ElementHandle> AddScriptTagAsync(AddTagOptions options)137        {138            const string addScriptUrl = @"async function addScriptUrl(url, type) {139              const script = document.createElement('script');140              script.src = url;141              if(type)142                script.type = type;143              const promise = new Promise((res, rej) => {144                script.onload = res;145                script.onerror = rej;146              });147              document.head.appendChild(script);148              await promise;149              return script;150            }";151            const string addScriptContent = @"function addScriptContent(content, type = 'text/javascript') {152              const script = document.createElement('script');153              script.type = type;154              script.text = content;155              let error = null;156              script.onerror = e => error = e;157              document.head.appendChild(script);158              if (error)159                throw error;160              return script;161            }";162            async Task<ElementHandle> AddScriptTagPrivate(string script, string urlOrContent, string type)163            {164                var context = await GetExecutionContextAsync().ConfigureAwait(false);165                return (string.IsNullOrEmpty(type)166                        ? await context.EvaluateFunctionHandleAsync(script, urlOrContent).ConfigureAwait(false)167                        : await context.EvaluateFunctionHandleAsync(script, urlOrContent, type).ConfigureAwait(false)) as ElementHandle;168            }169            if (!string.IsNullOrEmpty(options.Url))170            {171                var url = options.Url;172                try173                {174                    return await AddScriptTagPrivate(addScriptUrl, url, options.Type).ConfigureAwait(false);175                }176                catch (PuppeteerException)177                {178                    throw new PuppeteerException($"Loading script from {url} failed");179                }180            }181            if (!string.IsNullOrEmpty(options.Path))182            {183                var contents = await AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);184                contents += "//# sourceURL=" + options.Path.Replace("\n", string.Empty);185                return await AddScriptTagPrivate(addScriptContent, contents, options.Type).ConfigureAwait(false);186            }187            if (!string.IsNullOrEmpty(options.Content))188            {189                return await AddScriptTagPrivate(addScriptContent, options.Content, options.Type).ConfigureAwait(false);190            }191            throw new ArgumentException("Provide options with a `Url`, `Path` or `Content` property");192        }193        internal async Task<ElementHandle> AddStyleTagAsync(AddTagOptions options)194        {195            const string addStyleUrl = @"async function addStyleUrl(url) {196              const link = document.createElement('link');197              link.rel = 'stylesheet';198              link.href = url;199              const promise = new Promise((res, rej) => {200                link.onload = res;201                link.onerror = rej;202              });203              document.head.appendChild(link);204              await promise;205              return link;206            }";207            const string addStyleContent = @"async function addStyleContent(content) {208              const style = document.createElement('style');209              style.type = 'text/css';210              style.appendChild(document.createTextNode(content));211              const promise = new Promise((res, rej) => {212                style.onload = res;213                style.onerror = rej;214              });215              document.head.appendChild(style);216              await promise;217              return style;218            }";219            if (!string.IsNullOrEmpty(options.Url))220            {221                var url = options.Url;222                try223                {224                    var context = await GetExecutionContextAsync().ConfigureAwait(false);225                    return (await context.EvaluateFunctionHandleAsync(addStyleUrl, url).ConfigureAwait(false)) as ElementHandle;226                }227                catch (PuppeteerException)228                {229                    throw new PuppeteerException($"Loading style from {url} failed");230                }231            }232            if (!string.IsNullOrEmpty(options.Path))233            {234                var contents = await AsyncFileHelper.ReadAllText(options.Path).ConfigureAwait(false);235                contents += "//# sourceURL=" + options.Path.Replace("\n", string.Empty);236                var context = await GetExecutionContextAsync().ConfigureAwait(false);237                return (await context.EvaluateFunctionHandleAsync(addStyleContent, contents).ConfigureAwait(false)) as ElementHandle;238            }239            if (!string.IsNullOrEmpty(options.Content))240            {241                var context = await GetExecutionContextAsync().ConfigureAwait(false);242                return (await context.EvaluateFunctionHandleAsync(addStyleContent, options.Content).ConfigureAwait(false)) as ElementHandle;243            }244            throw new ArgumentException("Provide options with a `Url`, `Path` or `Content` property");245        }246        internal async Task ClickAsync(string selector, ClickOptions options = null)247        {248            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);249            if (handle == null)250            {251                throw new SelectorException($"No node found for selector: {selector}", selector);252            }253            await handle.ClickAsync(options).ConfigureAwait(false);254            await handle.DisposeAsync().ConfigureAwait(false);255        }256        internal async Task HoverAsync(string selector)257        {258            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);259            if (handle == null)260            {261                throw new SelectorException($"No node found for selector: {selector}", selector);262            }263            await handle.HoverAsync().ConfigureAwait(false);264            await handle.DisposeAsync().ConfigureAwait(false);265        }266        internal async Task FocusAsync(string selector)267        {268            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);269            if (handle == null)270            {271                throw new SelectorException($"No node found for selector: {selector}", selector);272            }273            await handle.FocusAsync().ConfigureAwait(false);274            await handle.DisposeAsync().ConfigureAwait(false);275        }276        internal async Task<string[]> SelectAsync(string selector, params string[] values)277        {278            if (!((await QuerySelectorAsync(selector).ConfigureAwait(false)) is ElementHandle handle))279            {280                throw new SelectorException($"No node found for selector: {selector}", selector);281            }282            var result = await handle.SelectAsync(values).ConfigureAwait(false);283            await handle.DisposeAsync();284            return result;285        }286        internal async Task TapAsync(string selector)287        {288            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);289            if (handle == null)290            {291                throw new SelectorException($"No node found for selector: {selector}", selector);292            }293            await handle.TapAsync().ConfigureAwait(false);294            await handle.DisposeAsync().ConfigureAwait(false);295        }296        internal async Task TypeAsync(string selector, string text, TypeOptions options = null)297        {298            var handle = await QuerySelectorAsync(selector).ConfigureAwait(false);299            if (handle == null)300            {301                throw new SelectorException($"No node found for selector: {selector}", selector);302            }303            await handle.TypeAsync(text, options).ConfigureAwait(false);304            await handle.DisposeAsync().ConfigureAwait(false);305        }306        internal Task<ElementHandle> WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null)307            => WaitForSelectorOrXPathAsync(selector, false, options);308        internal Task<ElementHandle> WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null)309            => WaitForSelectorOrXPathAsync(xpath, true, options);310        internal Task<JSHandle> WaitForFunctionAsync(string script, WaitForFunctionOptions options, params object[] args)311            => new WaitTask(312                this,313                script,314                false,315                "function",316                options.Polling,317                options.PollingInterval,318                options.Timeout ?? _timeoutSettings.Timeout,319                args).Task;320        internal Task<JSHandle> WaitForExpressionAsync(string script, WaitForFunctionOptions options)321            => new WaitTask(322                this,323                script,324                true,325                "function",326                options.Polling,327                options.PollingInterval,328                options.Timeout ?? _timeoutSettings.Timeout).Task;329        internal Task<string> GetTitleAsync() => EvaluateExpressionAsync<string>("document.title");330        private async Task<ElementHandle> GetDocument()331        {332            if (_documentCompletionSource == null)333            {334                _documentCompletionSource = new TaskCompletionSource<ElementHandle>(TaskCreationOptions.RunContinuationsAsynchronously);335                var context = await GetExecutionContextAsync().ConfigureAwait(false);336                var document = await context.EvaluateExpressionHandleAsync("document").ConfigureAwait(false);337                _documentCompletionSource.TrySetResult(document as ElementHandle);338            }339            return await _documentCompletionSource.Task.ConfigureAwait(false);340        }341        private async Task<ElementHandle> WaitForSelectorOrXPathAsync(string selectorOrXPath, bool isXPath, WaitForSelectorOptions options = null)342        {343            options = options ?? new WaitForSelectorOptions();344            var timeout = options.Timeout ?? _timeoutSettings.Timeout;345            const string predicate = @"346              function predicate(selectorOrXPath, isXPath, waitForVisible, waitForHidden) {347                const node = isXPath348                  ? document.evaluate(selectorOrXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue349                  : document.querySelector(selectorOrXPath);350                if (!node)351                  return waitForHidden;352                if (!waitForVisible && !waitForHidden)353                  return node;354                const element = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;355                const style = window.getComputedStyle(element);...Methods.cs
Source:Methods.cs  
...255            var frame = GetFrame(data);256            var options = new WaitForSelectorOptions { Hidden = hidden, Visible = visible, Timeout = timeout };257            if (findBy == FindElementBy.XPath)258            {259                await frame.WaitForXPathAsync(identifier, options);260            }261            else262            {263                await frame.WaitForSelectorAsync(BuildSelector(findBy, identifier), options);264            }265            data.Logger.Log($"Waited for element with {findBy} {identifier}", LogColors.DarkSalmon);266        }267        private static async Task<ElementHandle> GetElement(Frame frame, FindElementBy findBy, string identifier, int index)268        {269            var elements = findBy == FindElementBy.XPath270                ? await frame.XPathAsync(identifier)271                : await frame.QuerySelectorAllAsync(BuildSelector(findBy, identifier));272            if (elements.Length < index + 1)273            {274                throw new Exception($"Expected at least {index + 1} elements to be found but {elements.Length} were found");275            }276            return elements[index];277        }278        private static string GetElementsScript(FindElementBy findBy, string identifier)279        {280            if (findBy == FindElementBy.XPath)281            {282                var script = $"document.evaluate(\"{identifier.Replace("\"", "\\\"")}\", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)";283                return $"Array.from({{ length: {script}.snapshotLength }}, (_, index) => {script}.snapshotItem(index))";284            }...Program.cs
Source:Program.cs  
...97                    }98                    Console.WriteLine(string.Format("waiting for page to load properly (around {0} second)", pageLoadingTime/1000));99                    await page.WaitForTimeoutAsync(pageLoadingTime);100                    var iframeXpath = GoogleAds.GetMainIframeXpath();101                    var resultt = await page.XPathAsync(iframeXpath);102                    Console.WriteLine("Looking for Google Ads Banner");103                    int bannerCount = 0;104                    for (int j = 0; j < resultt.Length; j++)105                    {106                        var isVisible = await resultt[j].BoundingBoxAsync();107                        if (isVisible != null)108                        {109                            try110                            {111                                //get Iframe Content from page                       112                                var iFrame = await resultt[j].ContentFrameAsync();113                                //check if Iframe has Href that redirects to ads page, if not there is no ads114                                var anchorTagWithHref = await iFrame.XPathAsync(GoogleAds.GetAdsHrefXpath());115                                if (anchorTagWithHref != null && anchorTagWithHref.Length > 0)116                                {117                                    bannerCount++;118                                    Console.WriteLine("Found Google Ads Banner : " + bannerCount);119                                    var hrefValue = await anchorTagWithHref[0].EvaluateFunctionAsync<string>("e => e.href", anchorTagWithHref[0]);120                                    // extract Ads url . currently Query Key is "adurl". 121                                    Uri myUri = new Uri(hrefValue);122                                    string adsUrl = HttpUtility.ParseQueryString(myUri.Query).Get("adurl");123                                    var fileName = await GetBannerName(page, bannerCount);124                                    await Program.SavePageScreenShot(fileName, resultt[j]);125                                    GoogleLog.LogGoogleAds(fileName + ".png", adsUrl);126                                }127                            }128                            catch (Exception ex)...WinamaxEventScraper.cs
Source:WinamaxEventScraper.cs  
...44        public async Task<OutcomesSnapshot> ScrapPage()45        {46            await Page.GoToAsync(PageUri());47            //string content = await Page.GetContentAsync();48            var scripts = await Page.XPathAsync("//script");49            // Get <script> element containing preloaded state as Javascript object50            string jsData = null;51            foreach (var script in scripts)52            {53                var innerText = await script.GetPropertyAsync("innerText");54                var jsonValue = await innerText.JsonValueAsync();55                var text = jsonValue.ToString();56                Match match = _preloadedStateRegex.Match(text);57                if (match.Success)58                {59                    jsData = match.Groups[1].Value;60                    break;61                }62            }63            var liveElem = await Page.XPathAsync("//div[contains(@class, 'sc-ileJJU')]");64            bool isLive = liveElem.Length > 0;65            dynamic json = JsonConvert.DeserializeObject(jsData);66            var oddsDict = ParseOdds(json["odds"]);67            var outcomes = ParseOutcomes(json["outcomes"], oddsDict);68            return new OutcomesSnapshot(69                @event: _platformEvent,70                createdAt: DateTime.Now,71                state: isLive ? PlatformEventState.Live : PlatformEventState.Open,  // @todo72                outcomes: outcomes);73        }74        private readonly Regex _preloadedStateRegex = new Regex(@"^var PRELOADED_STATE =(.*);var");75        public string PageUri()76        {77            return $"https://www.winamax.fr/paris-sportifs/match/live/{_platformEvent.PlatformId}";...汽车之家.cs
Source:汽车之家.cs  
...23            //  await page.WaitForTimeoutAsync(10000);24            // var frame1 = page.Frames.First(f => f.Name == "frame1");25            //    var frame2 = page.MainFrame;26            //   var frame1 = frame2.ChildFrames.First();27            //    var waitForXPathPromise = frame1.WaitForXPathAsync("//div");28            //var test=await    frame1.GetContentAsync();29            //  var ifrmElement = await page.WaitForSelectorAsync("#reply-list");30            // ifrmElement.31            //var ifrmFrame = await ifrmElement.ContentFrameAsync();32            //var ifrmHtml = await ifrmFrame.GetContentAsync();33            // var test  = await page.SelectAsync("#J-datetime-select > a:nth-child(3)");34            var result = new List<CarFamilyDatas>();35            int n = 0;36            while (n++ < 29)37            {38                CreateModelWithAngleSharp(await page.GetContentAsync(), result);39                await page.ClickAsync("#topPager > div > a.page-item-next");40            }41            CarFamilyDatas.IntrusiveExport(result);42            //var replaylist = await page.SelectAsync("#reply-list");43    44            ////  await  ifrmElement.ClickAsync();45            //var ifrmElement1 = await page.XPathAsync("//*[@id=\"reply-item-72217813\"]");46            //await ifrmElement1[0].ClickAsync();47            //await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");48            //var beginDate = await page.SelectAsync("#beginDate");49            //await page.ClickAsync("#beginDate");50            //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");51            //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");52            //await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");53            //await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");54            //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");55            //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");56            //await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");57            //await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");58            //await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");59            //await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");...RunChoutiCraper.cs
Source:RunChoutiCraper.cs  
...23            //  await page.WaitForTimeoutAsync(10000);24            // var frame1 = page.Frames.First(f => f.Name == "frame1");25            //    var frame2 = page.MainFrame;26            //   var frame1 = frame2.ChildFrames.First();27            //    var waitForXPathPromise = frame1.WaitForXPathAsync("//div");28            //var test=await    frame1.GetContentAsync();29            //  var ifrmElement = await page.WaitForSelectorAsync("#reply-list");30            // ifrmElement.31            //var ifrmFrame = await ifrmElement.ContentFrameAsync();32            //var ifrmHtml = await ifrmFrame.GetContentAsync();33            // var test  = await page.SelectAsync("#J-datetime-select > a:nth-child(3)");34            var result = new List<CarFamilyDatas>();35            int n = 0;36            while (n++ < 29)37            {38                CreateModelWithAngleSharp(await page.GetContentAsync(), result);39                await page.ClickAsync("#topPager > div > a.page-item-next");40            }41            CarFamilyDatas.IntrusiveExport(result);42            //var replaylist = await page.SelectAsync("#reply-list");43            ////  await  ifrmElement.ClickAsync();44            //var ifrmElement1 = await page.XPathAsync("//*[@id=\"reply-item-72217813\"]");45            //await ifrmElement1[0].ClickAsync();46            //await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");47            //var beginDate = await page.SelectAsync("#beginDate");48            //await page.ClickAsync("#beginDate");49            //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");50            //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");51            //await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");52            //await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");53            //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");54            //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");55            //await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");56            //await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");57            //await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");58            //await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");...zhifubao.cs
Source:zhifubao.cs  
...19            //  await page.WaitForTimeoutAsync(10000);20            // var frame1 = page.Frames.First(f => f.Name == "frame1"); 21            //    var frame2 = page.MainFrame;22            //   var frame1 = frame2.ChildFrames.First(); 23            //    var waitForXPathPromise = frame1.WaitForXPathAsync("//div");24            //var test=await    frame1.GetContentAsync();25            var ifrmElement = await page.WaitForSelectorAsync("#J-datetime-select > a:nth-child(3)");26            // ifrmElement.27            //var ifrmFrame = await ifrmElement.ContentFrameAsync();28            //var ifrmHtml = await ifrmFrame.GetContentAsync();29            // var test  = await page.SelectAsync("#J-datetime-select > a:nth-child(3)");30            await page.ClickAsync("#J-datetime-select > a:nth-child(3)");31            await page.ClickAsync("body > div:nth-child(19) > ul > li:nth-child(5)");32            //  await  ifrmElement.ClickAsync();33            var ifrmElement1 = await page.XPathAsync("/html/body/div[10]/ul/li[5]");34            await ifrmElement1[0].ClickAsync();35            await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");36            var beginDate = await page.SelectAsync("#beginDate");37            await page.ClickAsync("#beginDate");38            await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");39            await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");40            await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");41            await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");42            await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");43            await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");44            await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");45            await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");46            await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");47            await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");...Clean163Email.cs
Source:Clean163Email.cs  
...24                await user.TypeAsync("");25                var password = await frame.WaitForSelectorAsync("input[data-placeholder='è¾å
¥å¯ç ']");26                await password.TypeAsync("");27                await frame.ClickAsync("#dologin");28                var element = await page.WaitForXPathAsync("//*[a='æ¸
çé®ç®±']");29                var cleanBtn = await element.XPathAsync("a[1]");30                await cleanBtn[0].ClickAsync();31                await Task.Delay(3000);32                var frame2 = page.Frames.First(s => s.Name.Contains("frmoutlink"));33                34                await frame2.ClickAsync("#clearTypeDate");35                      36                await frame2.ClickAsync("#dateCleanCustom");37                      38                await frame2.TypeAsync("#customYearStartIpt", "1990");39                await frame2.TypeAsync("#customMonthStartIpt", "1");40                await frame2.TypeAsync("#customDayStartIpt", "1");41                await frame2.TypeAsync("#customYearEndIpt", "2021");42                await frame2.TypeAsync("#customMonthEndIpt", "2");43                await frame2.TypeAsync("#customDayEndIpt", "18");44                var wait = new WaitForSelectorOptions {Timeout = 5000};45                for (int i = 0; i < 100000; i++)46                {47                    try48                    {49                        var b1 = await frame2.WaitForXPathAsync("//*/div[span='å¼å§æ«æ']", wait);50                        await b1.ClickAsync();51                        await Task.Delay(5000);52                        var deleteBtn = await frame2.WaitForXPathAsync("//div[span='å½»åºå é¤']", wait);53                        await deleteBtn.ClickAsync();54                        var confirmBtn = await page.WaitForXPathAsync("//div[span='ç¡® å®']", wait);55                        await confirmBtn.ClickAsync();56                        await Task.Delay(4000);57                        var confirm2Btn = await page.WaitForXPathAsync("//div[span='ç¡® å®']", wait);58                        await confirm2Btn.ClickAsync();59                    }60                    catch (Exception e)61                    {62                        Console.WriteLine(e);63                    }64                }65            }66        }67    }68}...XPathAsync
Using AI Code Generation
1using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))2{3    var page = await browser.NewPageAsync();4    var frame = page.MainFrame;5    await page.ScreenshotAsync("screenshot.png");6    await browser.CloseAsync();7}8using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))9{10    var page = await browser.NewPageAsync();11    var frame = page.MainFrame;12    var elementHandle = result.FirstOrDefault();13    await page.ScreenshotAsync("screenshot.png");14    await browser.CloseAsync();15}16using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))17{18    var page = await browser.NewPageAsync();19    var frame = page.MainFrame;20    var elementHandle = result.FirstOrDefault();21    var elementHandle2 = result2.FirstOrDefault();22    await page.ScreenshotAsync("screenshot.png");23    await browser.CloseAsync();24}25using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))26{27    var page = await browser.NewPageAsync();28    var frame = page.MainFrame;29    var elementHandle = result.FirstOrDefault();XPathAsync
Using AI Code Generation
1using System;2using System.Linq;3using System.Threading.Tasks;4using PuppeteerSharp;5{6    {7        static void Main(string[] args)8        {9            MainAsync().Wait();10        }11        static async Task MainAsync()12        {13            using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))14            {15                var page = await browser.NewPageAsync();16                var element = result.FirstOrDefault();17                await element.TypeAsync("PuppeteerSharp");18                await page.PressAsync("input", "Enter");19                await page.WaitForNavigationAsync();20            }21        }22    }23}XPathAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5    {6        static async Task Main(string[] args)7        {8            Console.WriteLine("Hello World!");9            await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);10            var browser = await Puppeteer.LaunchAsync(new LaunchOptions11            {12            });13            var page = await browser.NewPageAsync();14            await searchBox[0].TypeAsync("PuppeteerSharp");15            await page.Keyboard.PressAsync("Enter");16            await page.WaitForNavigationAsync();17            await page.ScreenshotAsync("google.png");18            await browser.CloseAsync();19        }20    }21}22I am a passionate software developer with 8+ years of experience in web development. I am currently working as a Senior Software Developer at Sopra Steria. I am a Microsoft Certified Professional in ASP.NET MVC 5.0 and have completed the Microsoft Certified Professional Developer (XPathAsync
Using AI Code Generation
1var puppeteer = require("puppeteer");2(async () => {3    var browser = await puppeteer.launch();4    var page = await browser.newPage();5    await page.goto(url);6    var result = await page.$x(xpath);7    console.log(result);8    await browser.close();9})();10var puppeteer = require("puppeteer");11(async () => {12    var browser = await puppeteer.launch();13    var page = await browser.newPage();14    await page.goto(url);15    var result = await page.$x(xpath);16    console.log(result);17    await browser.close();18})();19var puppeteer = require("puppeteer");20(async () => {21    var browser = await puppeteer.launch();22    var page = await browser.newPage();23    await page.goto(url);24    var result = await page.$x(xpath);25    console.log(result);26    await browser.close();27})();28var puppeteer = require("puppeteer");29(async () => {30    var browser = await puppeteer.launch();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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
