当前位置: 首页>>代码示例>>C#>>正文


C# IBrowser.WaitForAjax方法代码示例

本文整理汇总了C#中IBrowser.WaitForAjax方法的典型用法代码示例。如果您正苦于以下问题:C# IBrowser.WaitForAjax方法的具体用法?C# IBrowser.WaitForAjax怎么用?C# IBrowser.WaitForAjax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBrowser的用法示例。


在下文中一共展示了IBrowser.WaitForAjax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BrowserInitialize

		private Task BrowserInitialize(IBrowser browser, string icn, CancellationToken ct)
		{
			return Task.Run(async () =>
			{
				await browser.Navigate(ModuleConfiguration.Url, ct);
				do
				{
					var isJquery = (bool)await browser.ExecuteJs("return jQuery != null", ct);
					if (isJquery)
						break;

					await browser.Refresh(ct);
				} while (true);

				await browser.ExecuteJs(
					"window.fragma=window.fragma||{},fragma.modules=fragma.modules||{},void 0===fragma.modules.cities&&(fragma.modules.cities=new function(){var e=this,t=function(e,t,i,n,r){i.hide(),t.val(e),t.keydown();var a=[],o=function(){return i.is(':visible')?$.each(i.find('a'),function(e,t){var i=$(t);a.push(i.html())}):t.val()!=e&&a.push(t.val()),a.length>0?(n.waitHandler=null,void r(a)):void(n.waitHandler=setTimeout(o,100))};n.waitHandler=setTimeout(o,30)};e.senderContext={cities:[],waitHandler:null},e.receiverContext={cities:[],waitHandler:null},e.getSenderCity=function(i){e.senderContext.cities=[],e.senderContext.waitHandler&&(clearTimeout(e.senderContext.waitHandler),e.senderContext.waitHandler=null);var n=$('input[name=\"from_ship\"]'),r=$($('ul.ui-autocomplete')[0]);t(i,n,r,e.senderContext,function(t){e.senderContext.cities=t})},e.getReceiverCity=function(i){e.receiverContext.cities=[],e.receiverContext.waitHandler&&(clearTimeout(e.receiverContext.waitHandler),e.receiverContext.waitHandler=null);var n=$('input[name=\"to_send\"]'),r=$($('ul.ui-autocomplete')[1]);return t(i,n,r,e.receiverContext,function(t){e.receiverContext.cities=t})}});",
					ct);

				await browser.ExecuteJs(
					"window.fragma=window.fragma||{},fragma.modules=fragma.modules||{},void 0===fragma.modules.tariffs&&(fragma.modules.tariffs=new function(){var a=this;a.getTariffs=function(){for(var a=[],n=$('.style_table').find('tr'),r=1;r<n.length;++r){var f=$(n[r]);$columns=f.find('td');var s=$columns[0].innerHTML,m=$($columns[1]).find('b').html(),i=$columns[2].innerHTML;a.push(s),a.push(m),a.push(i)}return a}});",
					ct);

				if (!await browser.Select("input[name='login']", ct))
					throw new InvalidOperationException("Can't find login input");
				await browser.Input(ModuleConfiguration.Login, ct);

				if (!await browser.Select("input[name=pass]", ct))
					throw new InvalidOperationException("Can't find password input");
				await browser.Input(ModuleConfiguration.Password, ct);

				if (!await browser.WaitForAjax(5000, ct))
					throw new TimeoutException("Failed to wait for icn input to show");

				//await WaitFor("Failed to wait for icn input to show", 20, () =>
				//{
				//    return _browser.IsElementVisible("div#loginform input[name=icn]", ct);
				//}, ct);

				if (!await browser.Select("input[name=icn]", ct))
					throw new InvalidOperationException("Can't find icn input");
				await browser.Input(icn, ct);
				await browser.Select("#submit", ct);

				if (!await browser.WaitForAjax(10000, ct))
					throw new TimeoutException("Login operation proceeded too long");
			}, ct);
		}
开发者ID:FragmaYOla,项目名称:TariffMeter,代码行数:47,代码来源:SPSRTariffsProvider.cs

示例2: GetTariffs

		private async Task<List<Tariff>> GetTariffs(IBrowser browser, CancellationToken ct)
		{
			await browser.Select("#spsr-calculator-form a.btn[onclick='calculate()']", ct);
			browser.Click();

			if (!await browser.WaitForAjax(10000, ct))
				throw new TimeoutException("Failed to wait for tariffs");

			var tariffsResponse = (await browser.ExecuteJs("return fragma.modules.tariffs.getTariffs()", ct) as IList);
			var sTariffs = new List<string>();
			foreach (var c in tariffsResponse)
				sTariffs.Add(c.ToString());

			var tariffs = new List<Tariff>();
			foreach (var tariffOptions in sTariffs.Chunk(3))
			{
				var tariff = new Tariff();
				var opts = tariffOptions.ToArray();
				tariff.ProviderType = TariffProviderType.SPSR;
				tariff.SubProviderName = opts[0];
				tariff.Price = decimal.Parse(opts[1].Split(' ').FirstOrDefault(), CultureInfo.InvariantCulture);
				tariff.DeliveryMethod = DeliveryMethod.ToTerminal;
				var times = opts[2].Split('-');
				var min = TimeSpan.Zero;
				min = new TimeSpan(int.Parse(times[0].Trim()), 0, 0, 0);
				var max = min;
				if (times.Count() > 1)
				{
					max = new TimeSpan(int.Parse(times[1].Trim()), 0, 0, 0);
				}
				tariff.MinDeliveryTime = min;
				tariff.MaxDeliveryTime = max;
				tariff.DeliveryTime = max;
				tariffs.Add(tariff);
			}

			return tariffs;
		}
开发者ID:FragmaYOla,项目名称:TariffMeter,代码行数:38,代码来源:SPSRTariffsProvider.cs


注:本文中的IBrowser.WaitForAjax方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。