private bool GetDocument(Element element, ref Lead lead) { try { _main.Actions.Click(element); //moves forward once var imageel =_find.ByAttributes("src=~https://www.sos.state.co.us/tmpdocs"); var image = new HtmlImage(imageel); if (image != null) { _main.Actions.ScrollToVisible(imageel); _imagelocation = Path.Combine(Properties.Settings.Default.pdfstore, lead.GetHashCode() + Path.GetExtension(image.Src)); WebRequest req = WebRequest.Create(image.Src); WebResponse response = req.GetResponse(); Image.FromStream(response.GetResponseStream()).Save(_imagelocation); return true; } } catch(Exception e) { Console.WriteLine(e.Message); lead.Messages.Add(new Message() { Content = e.Message, Messagetype = MessageType.Error }); } finally { _main.GoBack(); } return false; }
private bool GetDocument(Element element, ref Lead lead, bool viewerloaded) { var documentdound = false; try { var detailrow = GetFirstParentByTagName(element, "tr"); var tablerow = new HtmlTableRow(detailrow); var imageclick = tablerow.Find.ByCustom(e => e.Content.Contains("viewImageFrames.asp")); lead.Document.Url = GetUrlFromJavaPopHref(imageclick.Content); //add event listener //AddListener(); _main.Actions.Click(imageclick); //just wait for it to finish loading if (viewerloaded) Thread.Sleep(1000 * _config.Performancetweaks["imageviewerload"]); else Thread.Sleep(1000 * _config.Performancetweaks["imagewaitafterload"]); //documentdound = WaitForJavaApplet();); if (lead.Document.Pages > 0) { //RemoveListener= //try and use the save button //AddListener(Properties.Settings.Default.downloadpath); int x = _manager.ActiveBrowser.Window.Location.X + _config.Positionals["SavePdf"].X; int y = _manager.ActiveBrowser.Window.Location.Y + _config.Positionals["SavePdf"].Y; if (!_manager.ActiveBrowser.Window.IsVisible) { _manager.ActiveBrowser.Window.SetFocus(); } _manager.Desktop.Mouse.Click(MouseClickType.LeftClick, x, y ); Thread.Sleep(200); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); var path = Path.Combine(Properties.Settings.Default.pdfstore, lead.GetHashCode() + ".tif"); // var save = new SaveAsDialog(_manager.ActiveBrowser, DialogButton.SAVE, path, _manager.Desktop); // _manager.DialogMonitor.AddDialog(save); // _manager.DialogMonitor.Start(); _manager.Desktop.KeyBoard.KeyPress(Keys.Space); Thread.Sleep(_config.Performancetweaks["textdialogueload"] * 1000); _manager.Desktop.KeyBoard.TypeText(path, 100 ); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Tab); _manager.Desktop.KeyBoard.KeyPress(Keys.Enter); //handle save pop up documentdound = true; //handle file download pop up _manager.DialogMonitor.Stop(); } var test = _manager.ActiveBrowser.Url; Console.WriteLine(test); // if (!documentfound) // { //try once more // foreach (var browser in _manager.Browsers.Where(browser => browser.ClientId != _main.ClientId)) // { // browser.Close(); // } // _main.Actions.Click(imageclick); // WaitForJavaApplet(); // } foreach (var browser in _manager.Browsers.Where(browser => browser.ClientId != _main.ClientId)) { browser.Close(); } return documentdound; } catch (Exception e) { Console.WriteLine(e.Message); lead.Messages.Add(new Message() { Content = e.Message, Messagetype = MessageType.Error }); } finally { RemoveListener(); } return false; }