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); }
private async Task FillInParcelProperties(IBrowser browser, Parcel parcel, CancellationToken ct) { await browser.Select("select[name='EncloseType'] option[value='17']", ct); if (!await browser.Select("input[name='weight']", ct)) throw new InvalidOperationException("Can't find from parcel weight input"); await browser.Input(parcel.Weight.ToString(), ct); if (!await browser.Select("input[name='width']", ct)) throw new InvalidOperationException("Can't find from parcel width input"); await browser.Input(parcel.Size == Size._45x18x20 ? "20" : "40", ct); if (!await browser.Select("input[name='_length']", ct)) throw new InvalidOperationException("Can't find from parcel length input"); await browser.Input(parcel.Size == Size._45x28x39 ? "40" : "20", ct); if (!await browser.Select("input[name='height']", ct)) throw new InvalidOperationException("Can't find from parcel height input"); await browser.Input("50", ct); if (!await browser.Select("input[name='cost']", ct)) throw new InvalidOperationException("Can't find from parcel cost input"); await browser.Input(parcel.SendValue.ToString(), ct); await browser.ExecuteJs("$(\"input[name='type']\").click()", ct); }