How to use WaitTaskTimeoutException class of PuppeteerSharp package

Best Puppeteer-sharp code snippet using PuppeteerSharp.WaitTaskTimeoutException

WeiboFavScrape.cs

Source:WeiboFavScrape.cs Github

copy

Full Screen

...51 Visible = true, Timeout = 1500052 });53 Log.Logger.Information("User Login Success");54 }55 catch (WaitTaskTimeoutException)56 {57 Log.Logger.Information("Try Login...");58 await Login(page);59 }60 while (true)61 {62 try63 {64 url = "https://weibo.com/fav?leftnav=1";65 await page.GoToAsync(url);66 Log.Logger.Information("Checking fav Weibo...");67 await page.WaitForSelectorAsync(".WB_feed_like", new WaitForSelectorOptions {Visible = true});68 var weibos = await page.QuerySelectorAllAsync(".WB_feed_like");69 var weiboInfoList = new List<WeiboInfo>();70 foreach (var element in weibos)71 {72 var mid = await element.GetAttributeAsync("mid", page);73 var ninePicTrigger = await element.QuerySelectorAllAsync(".WB_pic.li_9");74 if (ninePicTrigger.Any())75 {76 await ninePicTrigger[0].ClickAsync();77 await page.WaitForSelectorAsync($"[mid='{mid}'] .WB_expand_media_box",78 new WaitForSelectorOptions {Visible = true});79 }80 var html = await page.EvaluateFunctionAsync<string>("(el) => el.innerHTML", element);81 var urlElement =82 await element.QuerySelectorAsync(".WB_func li:nth-child(2) a");83 var imgBoxesElement =84 await element.QuerySelectorAsync(".WB_media_a[action-data]");85 weiboInfoList.Add(new WeiboInfo86 {87 Id = mid,88 RawHtml = html,89 Url = urlElement != null90 ? "https://weibo.com" + await urlElement.GetAttributeAsync("href", page)91 : "",92 ImgUrls = (await Task.WhenAll(93 PulloutImgList(imgBoxesElement != null94 ? await imgBoxesElement.GetAttributeAsync("action-data", page)95 : "")96 .Select(async d => new Img97 {98 ImgUrl = $"https://wx1.sinaimg.cn/large/{d}",99 ImgPath = await DownloadImg($"https://wx1.sinaimg.cn/large/{d}")100 }))).ToList()101 });102 }103 using (var db = new Database())104 {105 // ReSharper disable once AccessToDisposedClosure106 weiboInfoList = weiboInfoList.Where(t => db.WeiboInfo.All(d => t.Id != d.Id)).ToList();107 await db.WeiboInfo.AddRangeAsync(weiboInfoList);108 await db.SaveChangesAsync();109 }110 File.Delete("screenshot.png");111 await page.ScreenshotAsync("screenshot.png");112 Log.Logger.Information($"Find {weiboInfoList.Count} new weibos");113 if (weiboInfoList.Count > 0)114 Log.Logger.Information("Passing weibos to telegram bot...");115 foreach (var weiboInfo in weiboInfoList)116 WeiboReceived?.Invoke(this, new WeiboEventArgs {WeiboInfo = weiboInfo});117 }118 catch (Exception e)119 {120 if (e is PuppeteerException)121 //Log.Fatal(e, "Browser dead");122 throw;123 Log.Fatal(e, "Access Weibo failed");124 }125 await Task.Delay(TimeSpan.FromMinutes(1));126 }127 }128 }129 private IEnumerable<string> PulloutImgList(string html)130 {131 var listOnlyNinePic = ImgUrlRegex.Matches(html).Select(d => d.Value);132 var allPic = ImgUrlRegexNew.Match(html).Value.Split(',', StringSplitOptions.RemoveEmptyEntries)133 .Select(t => $"{t}.jpg");134 return listOnlyNinePic.Concat(allPic).Distinct();135 }136 private async Task Login(Page page)137 {138 await page.WaitForSelectorAsync("[name=username]", new WaitForSelectorOptions {Visible = true});139 var username = await page.QuerySelectorAsync("[name='username']");140 var password = await page.QuerySelectorAsync("[name='password']");141 var submitBtn = await page.QuerySelectorAsync("div[node-type='normal_form'] a[node-type='submitBtn']");142 await username.ClickAsync();143 await username.FocusAsync();144 // click three times to select all145 await username.ClickAsync(new ClickOptions {ClickCount = 3});146 await username.PressAsync("Backspace");147 await username.TypeAsync(Program.Config["Weibo:Username"]);148 await password.ClickAsync();149 await password.FocusAsync();150 // click three times to select all151 await password.ClickAsync(new ClickOptions {ClickCount = 3});152 await password.PressAsync("Backspace");153 await password.TypeAsync(Program.Config["Weibo:Password"]);154 await submitBtn.ClickAsync();155 while (true)156 try157 {158 await page.WaitForSelectorAsync(".WB_left_nav", new WaitForSelectorOptions {Visible = true});159 break;160 }161 catch (WaitTaskTimeoutException)162 {163 if (await page.QuerySelectorAsync("#dmCheck") == null)164 {165 Code = "";166 File.Delete("verify.png");167 await page.ScreenshotAsync("verify.png");168 Console.WriteLine("Please check verify.png for verify code");169 using (var verifyImgStream = await page.ScreenshotStreamAsync())170 {171 VerifyRequested?.Invoke(this, new VerifyEventArgs {VerifyImg = verifyImgStream});172 }173 while (string.IsNullOrWhiteSpace(Code))174 {175 Log.Logger.Information("Waiting for verify code...");...

Full Screen

Full Screen

PageActor.cs

Source:PageActor.cs Github

copy

Full Screen

...108 new WaitForSelectorOptions { Visible = true, Timeout = 30000 }109 );110 await acceptCookiesButtonVisible.ClickAsync(new ClickOptions() { Delay = 1000 });111 }112 catch (WaitTaskTimeoutException ex) // Only catches WaitTaskTimeoutException exceptions.113 {114 }115 }116 bool isLoadMoreButtonVisible = await ScrollPageUntilHtmlElementIsVisible(Configuration.XpathForLoadMoreButton);117 if (isLoadMoreButtonVisible)118 {119 bool hasMoreContent = true;120 while (hasMoreContent)121 {122 try123 {124 var loadMoreButton = await Page.WaitForXPathAsync(125 Configuration.XpathForLoadMoreButton,126 new WaitForSelectorOptions { Visible = true, Timeout = 30000 }127 );128 await loadMoreButton.ClickAsync(new ClickOptions() { Delay = 1000 });129 }130 catch (WaitTaskTimeoutException ex) // Only catches WaitTaskTimeoutException exceptions.131 {132 hasMoreContent = false;133 }134 }135 }136 foreach (var xpath in Configuration.AbsoluteXpathsForElementsToEnsureExist)137 {138 bool isElementVisible = await ScrollPageUntilHtmlElementIsVisible(xpath);139 if (isElementVisible == false) // xpathsForDesiredHtmlElements has a treestructure, so we want to break out of the loop as soon as possible when not found.140 {141 break;142 }143 }144 }145 private async Task<bool> ScrollPageUntilHtmlElementIsVisible(string xpath) // TODO REFACTOR146 {147 if (xpath != null)148 {149 int attempt = 1;150 int attemptLimit = 3; // TODO Should be configurable151 int currentHeight = (int)await Page.EvaluateExpressionAsync("document.body.scrollHeight");152 while (attempt <= attemptLimit)153 {154 try155 {156 await Page.WaitForXPathAsync(157 xpath,158 new WaitForSelectorOptions { Visible = true, Timeout = 2500 }159 );160 return true;161 }162 catch (WaitTaskTimeoutException ex) // Only catches WaitTaskTimeoutException exceptions.163 {164 int newHeight = (int)await Page.EvaluateExpressionAsync("document.body.scrollHeight");165 await Page.EvaluateExpressionAsync("window.scrollBy({top:" + newHeight + ",behavior:'smooth'})"); // To trigger autoload of new content.166 if (currentHeight == newHeight)167 {168 break;169 }170 currentHeight = newHeight;171 }172 attempt++;173 }174 }175 return false;176 }...

Full Screen

Full Screen

LogsController.cs

Source:LogsController.cs Github

copy

Full Screen

...164 await page.ClickAsync("button[type='button'][mode='primary']");165 }166 catch (Exception e)167 {168 if (e.GetType().ToString() == "PuppeteerSharp.NavigationException" || e.GetType().ToString() == "PuppeteerSharp.WaitTaskTimeoutException")169 {170 await page.CloseAsync();171 await page.DisposeAsync();172 return null;173 }174 Console.WriteLine(e);175 }176 var element = await page.QuerySelectorAsync("#view-tabs-and-table-container");177 image = await element.ScreenshotDataAsync();178179 await page.CloseAsync();180 await page.DisposeAsync();181182 return image; ...

Full Screen

Full Screen

Get-ScraperMobileVikings.cs

Source:Get-ScraperMobileVikings.cs Github

copy

Full Screen

...73 credits = decimal.Parse(creditText, CultureInfo.InvariantCulture.NumberFormat);74 } else {75 throw new Exception($"Credits not found ({creditText})");76 }77 } catch (PuppeteerSharp.WaitTaskTimeoutException) {78 var creditField = await page.WaitForSelectorAsync(79 "body > div:nth-child(1) > div:nth-child(3) > div > div > main > div > section > div > section > section");80 var creditText = await creditField.EvaluateFunctionAsync<string>("e => e.innerText");81 if (creditText.Contains("Geen\nbelwaarde"))82 credits = 0m;83 else84 throw new Exception($"Credits not found (No credits left?)");85 }8687 // Get points88 System.Threading.Thread.Sleep(3000);89 decimal? points = null;90 if (!DontIncludePoints)91 { ...

Full Screen

Full Screen

BadmintonClient.cs

Source:BadmintonClient.cs Github

copy

Full Screen

...62 {63 Timeout = 500064 });65 }66 catch (WaitTaskTimeoutException)67 {68 var results =69 await page.EvaluateFunctionAsync<List<BadmintonAvailability>>(InjectionScripts70 .GetAllBadmintonAvailabilityForPage);71 var selectedAvailability = results.First(x => x.Code == availabilityCode);72 if (selectedAvailability.Status != BadmintonAvailabilityStatus.Current)73 throw new Exception("Court is no longer available");74 // Click on the Register button in the list of available courts75 await page.ClickAsync("#u5200_btnButtonRegister0");76 await page.WaitForSelectorAsync("#u3600_btnSelect0");77 }78 79 await page.ClickAsync("#u3600_btnSelect0");80 81 // Hard timeouts because Loisir website has a very slim window where the button cannot be clicked82 // Which causes Pupperteer to think it has successfully clicked on the button when it didn't83 84 // Click on Cart section finished button85 await page.WaitForSelectorAsync("#u3600_btnCheckout0");86 await page.WaitForTimeoutAsync(1000);87 await page.ClickAsync("#u3600_btnCheckout0");88 89 // Click on the Confirm button90 await page.WaitForSelectorAsync("#u3600_btnCartShoppingCompleteStep");91 await page.WaitForTimeoutAsync(1000);92 await page.ClickAsync("#u3600_btnCartShoppingCompleteStep");93 94 // Accept Terms & services95 await page.WaitForSelectorAsync("#u3600_chkElectronicPaymentCondition");96 await page.WaitForTimeoutAsync(1000);97 await page.ClickAsync("#u3600_chkElectronicPaymentCondition");98 99 // Click on the Confirm button100 await page.WaitForSelectorAsync("#u3600_btnCartPaymentCompleteStep");101 await page.WaitForTimeoutAsync(1000);102 await page.ClickAsync("#u3600_btnCartPaymentCompleteStep");103 }104 105 private async Task Login(Page page, BadmintonCredentials credentials)106 {107 try108 {109 await page.WaitForSelectorAsync("#formpr", new WaitForSelectorOptions110 {111 Timeout = 2000112 });113 } 114 catch (WaitTaskTimeoutException)115 {116 // Sometimes Loisir page does not redirect you to the login page117 // if it doesn't, click on login button manually118 await page.ClickAsync("#u2000_btnSignIn");119 await page.WaitForSelectorAsync("#formpr");120 }121 await page.TypeAsync("input[name=Email]#Email", credentials.Email);122 await page.TypeAsync("input[name=Password]#Password", credentials.Password);123 await page.ClickAsync("input[type=submit].bt-connexion");124 await page.WaitForNavigationAsync(new NavigationOptions125 {126 WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded },127 });128 ...

Full Screen

Full Screen

GenerateStatic.cs

Source:GenerateStatic.cs Github

copy

Full Screen

...54 {55 Timeout = MyConfig.timeout56 });57 }58 catch (WaitTaskTimeoutException)59 {60 PluginHelper.printConsole($"Wait already {MyConfig.timeout} ms. Get html now.");61 }62 string htmlContent = await page.GetContentAsync();63 Directory.CreateDirectory(prerender);64 await WriteTextAsync(prerenderIndex, htmlContent);65 }66 else UseCacheCount++;67 Directory.CreateDirectory(dist);68 if (prerenderIndex != distIndex) File.Copy(prerenderIndex, distIndex, true);69 }70 catch (System.Exception ex)71 {72 if (!string.IsNullOrWhiteSpace(prerenderIndex) && File.Exists(prerenderIndex)) File.Delete(prerenderIndex);...

Full Screen

Full Screen

WaitTaskTimeoutException.cs

Source:WaitTaskTimeoutException.cs Github

copy

Full Screen

...5 /// <summary>6 /// Timeout exception that might be thrown by <c>WaitFor</c> methods in <see cref="Frame"/>.7 /// </summary>8 [Serializable]9 public class WaitTaskTimeoutException : PuppeteerException10 {11 /// <summary>12 /// Timeout that caused the exception13 /// </summary>14 /// <value>The timeout.</value>15 public int Timeout { get; }16 /// <summary>17 /// Element type the WaitTask was waiting for18 /// </summary>19 /// <value>The element.</value>20 public string ElementType { get; }21 /// <summary>22 /// Initializes a new instance of the <see cref="PuppeteerSharp.WaitTaskTimeoutException"/> class.23 /// </summary>24 public WaitTaskTimeoutException()25 {26 }27 /// <summary>28 /// Initializes a new instance of the <see cref="PuppeteerSharp.WaitTaskTimeoutException"/> class.29 /// </summary>30 /// <param name="message">Message.</param>31 public WaitTaskTimeoutException(string message) : base(message)32 {33 }34 /// <summary>35 /// Initializes a new instance of the <see cref="PuppeteerSharp.WaitTaskTimeoutException"/> class.36 /// </summary>37 /// <param name="timeout">Timeout.</param>38 /// <param name="elementType">Element type.</param>39 public WaitTaskTimeoutException(int timeout, string elementType) :40 base($"waiting for {elementType} failed: timeout {timeout}ms exceeded")41 {42 Timeout = timeout;43 ElementType = elementType;44 }45 /// <summary>46 /// Initializes a new instance of the <see cref="PuppeteerSharp.WaitTaskTimeoutException"/> class.47 /// </summary>48 /// <param name="message">Message.</param>49 /// <param name="innerException">Inner exception.</param>50 public WaitTaskTimeoutException(string message, Exception innerException) : base(message, innerException)51 {52 }53 /// <summary>54 /// Initializes a new instance of the <see cref="PuppeteerSharp.WaitTaskTimeoutException"/> class.55 /// </summary>56 /// <param name="info">Info.</param>57 /// <param name="context">Context.</param>58 protected WaitTaskTimeoutException(SerializationInfo info, StreamingContext context) : base(info, context)59 {60 }61 }62}...

Full Screen

Full Screen

PuppeteerSharpExtension.cs

Source:PuppeteerSharpExtension.cs Github

copy

Full Screen

...14 return frame;15 }16 await Task.Delay(1000);17 }18 throw new WaitTaskTimeoutException();19 }20 private static Frame FindFrame(Frame[] list, string[] nameList)21 {22 foreach (var frame in list)23 {24 foreach (var name in nameList)25 {26 if (frame.Name == name)27 {28 return frame;29 }30 }31 }32 return null;...

Full Screen

Full Screen

WaitTaskTimeoutException

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 var options = new LaunchOptions { Headless = false };9 var browser = await Puppeteer.LaunchAsync(options);10 var page = await browser.NewPageAsync();11 var waitTask = page.WaitForNavigationAsync();12 {13 await waitTask;14 }15 catch (WaitTaskTimeoutException e)16 {17 Console.WriteLine("Timeout: " + e.Message);18 }19 await browser.CloseAsync();20 }21 }22}

Full Screen

Full Screen

WaitTaskTimeoutException

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp;2{3 {4 public WaitTaskTimeoutException(string message) : base(message)5 {6 }7 }8}9using PuppeteerSharp;10{11 {12 public WaitTaskTimeoutException(string message) : base(message)13 {14 }15 }16}17using PuppeteerSharp;18{19 {20 public WaitTaskTimeoutException(string message) : base(message)21 {22 }23 }24}25using PuppeteerSharp;26{27 {28 public WaitTaskTimeoutException(string message) : base(message)29 {30 }31 }32}33using PuppeteerSharp;34{35 {36 public WaitTaskTimeoutException(string message) : base(message)37 {38 }39 }40}41using PuppeteerSharp;42{43 {44 public WaitTaskTimeoutException(string message) : base(message)45 {46 }47 }48}49using PuppeteerSharp;50{51 {52 public WaitTaskTimeoutException(string message) : base(message)53 {54 }55 }56}57using PuppeteerSharp;58{59 {

Full Screen

Full Screen

WaitTaskTimeoutException

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 Console.WriteLine("Hello World!");9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions10 {11 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",12 Args = new string[] { "--window-size=1920,1080" }13 });14 var page = await browser.NewPageAsync();15 await page.WaitForSelectorAsync("#lst-ib", new WaitForSelectorOptions { Timeout = 3000 });16 await page.TypeAsync("#lst-ib", "puppeteer-sharp");17 await page.WaitForSelectorAsync("input[value='Google Search']", new WaitForSelectorOptions { Timeout = 3000 });18 await page.ClickAsync("input[value='Google Search']");19 await page.WaitForSelectorAsync("div.g h3", new WaitForSelectorOptions { Timeout = 3000 });20 var searchResults = await page.QuerySelectorAllAsync("div.g h3");21 foreach (var searchResult in searchResults)22 {23 Console.WriteLine(await searchResult.EvaluateFunctionAsync<string>("node => node.inne

Full Screen

Full Screen

WaitTaskTimeoutException

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 var options = new LaunchOptions { Headless = false };9 using (var browser = await Puppeteer.LaunchAsync(options))10 using (var page = await browser.NewPageAsync())11 {12 await page.WaitForSelectorAsync("input[title='Search']");13 }14 }15 }16}17using PuppeteerSharp;18using System;19using System.Threading.Tasks;20{21 {22 static async Task Main(string[] args)23 {24 var options = new LaunchOptions { Headless = false };25 using (var browser = await Puppeteer.LaunchAsync(options))26 using (var page = await browser.NewPageAsync())27 {28 {29 await page.WaitForSelectorAsync("input[title='Search']");30 }31 catch (WaitTaskTimeoutException ex)32 {33 Console.WriteLine("Timeout Value: " + ex.Timeout);34 }35 }36 }37 }38}39using PuppeteerSharp;40using System;41using System.Threading.Tasks;42{43 {44 static async Task Main(string[] args)45 {46 var options = new LaunchOptions { Headless = false };47 using (var browser = await Puppeteer.LaunchAsync(options))48 using (var page = await browser.NewPageAsync())49 {50 {51 await page.WaitForSelectorAsync("input[title='Search']");52 }53 catch (WaitTaskTimeoutException ex)54 {55 Console.WriteLine("Timeout Value: " + ex.Timeout);56 }57 }58 }59 }60}

Full Screen

Full Screen

WaitTaskTimeoutException

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 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 {15 await page.WaitForSelectorAsync("input[title='Search']", new WaitForSelectorOptions16 {17 });18 }19 catch (WaitTaskTimeoutException e)20 {21 Console.WriteLine(e.Message);22 }23 await browser.CloseAsync();24 }25 }26}

Full Screen

Full Screen

WaitTaskTimeoutException

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 {9 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);10 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))11 using (var page = await browser.NewPageAsync())12 {13 await page.WaitForSelectorAsync(".gLFyf", new WaitForSelectorOptions { Timeout = 1000 });14 await page.TypeAsync(".gLFyf", "PuppeteerSharp");15 await page.WaitForSelectorAsync(".FPdoLc > center > input[name='btnK']", new WaitForSelectorOptions { Timeout = 1000 });16 await page.ClickAsync(".FPdoLc > center > input[name='btnK']");17 await page.WaitForSelectorAsync(".g", new WaitForSelectorOptions { Timeout = 1000 });18 }19 }20 catch (WaitTaskTimeoutException)21 {

Full Screen

Full Screen

WaitTaskTimeoutException

Using AI Code Generation

copy

Full Screen

1var browserFetcher = new BrowserFetcher();2await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);3var options = new LaunchOptions { Headless = true };4var browser = await Puppeteer.LaunchAsync(options);5var page = await browser.NewPageAsync();6await page.ScreenshotAsync("google.png");7await browser.CloseAsync();8var browserFetcher = new BrowserFetcher();9await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);10var options = new LaunchOptions { Headless = true };11var browser = await Puppeteer.LaunchAsync(options);12var page = await browser.NewPageAsync();13await page.ScreenshotAsync("google.png");14await browser.CloseAsync();

Full Screen

Full Screen

WaitTaskTimeoutException

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 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });9 var page = await browser.NewPageAsync();10 var searchBox = await page.QuerySelectorAsync("input[name=q]");11 await searchBox.TypeAsync("puppeteer");12 await page.Keyboard.PressAsync("Enter");13 {14 await page.WaitForSelectorAsync("div#result-stats", new WaitForSelectorOptions { Timeout = 1000 });15 }16 catch (WaitTaskTimeoutException)17 {18 Console.WriteLine("Search result not found");19 }20 await browser.CloseAsync();21 }22 }23}

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.

Most used methods in WaitTaskTimeoutException

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful