/// <summary> /// Screen Scrape Events /// </summary> /// <param name="query"></param> /// <returns></returns> static List<EventDetail> FetchEvents(string query) { var eventDetails = new List<EventDetail>(); using (var _browser = new IE("http://www.gettyimages.com", false)) { _browser.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide); _browser.TextField(Find.ById("txtPhrase")).Clear(); _browser.TextField(Find.ById("txtPhrase")).TypeText(query); var editorialChkfield = _browser.CheckBox(Find.ById("cbxEditorial")); if (!editorialChkfield.Checked) editorialChkfield.Click(); _browser.Button(Find.ById("btnSearch")).Click(); if (_browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Exists) { _browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Click(); _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent")).WaitUntilExists(); var filterContentDiv = _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent")); foreach (var link in filterContentDiv.Links.Filter(Find.ByClass("refineItem"))) { var splitList = link.OuterHtml.Split('\''); if (splitList.Length > 5) eventDetails.Add(new EventDetail() { EventId = int.Parse(splitList[1]), EventName = splitList[5].Trim() }); } } } return eventDetails; }
public void HomePageContainsPromotionPanel() { using (var browser = new IE("http://localhost:1200/")) { Assert.IsTrue(browser.Div(Find.ById("promotion")).Exists); } }
public static bool IsExist(IE ie, HControl control) { try { bool existed = true; Regex regex = new Regex(FilterPattern.GetToPattern(control.Value)); switch (control.Control.ToLower()) { case ControlType.AHref: existed = ie.Link(Find.ByText(regex)).Exists; break; case ControlType.AHrefNoText: try { } catch (Exception ex) { existed = false; } break; case ControlType.Button: existed = ie.Button(GetControl(ie, control)).Exists; break; case ControlType.Div: existed = ie.Div(GetControl(ie, control)).Exists; break; case ControlType.TextArea: existed = ie.TextField(GetControl(ie, control)).Exists; break; case ControlType.TextBox: existed = ie.TextField(GetControl(ie, control)).Exists; break; } return existed;// } catch (Exception ex) { return false; } }
public void LocatingThingsByNonId() { using (var browser = new IE("http://localhost:62727/Pages/ApplyForCreditCard.aspx")) { Div errorContainer = browser.Div(Find.ByClass("error")); SelectList title = browser.SelectList(Find.ByName("Title")); Label ageLabel = browser.Label(Find.ByFor("Age")); TextField applicantAge = browser.TextField(Find.ByLabelText("Age In Years")); TextField applicantAge2 = browser.TextField(Find.By("id", "Age")); // var something = browser.Div(Find.By("someattribute","somevalue")); // Assert.That(something, Is.Not.Null); // Link helpHyperlink = browser.Link(Find.ById("HelpLink")); // Button applyButton = browser.Button(Find.ById("ApplyNow")); // Para nameParagraph = browser.Para(Find.ById("Name")); } }
public void PopulateUrls() { Settings.AttachToBrowserTimeOut = 240; Settings.WaitUntilExistsTimeOut = 240; Settings.WaitForCompleteTimeOut = 240; using (var browser = new IE("http://www.youtube.com/user/vahchef/videos",true)) { Div mainDiv = browser.Div(Find.ById("video-page-content")); while (mainDiv.Buttons.Where(b => b.ClassName != null && b.ClassName.Contains("load-more-button")).FirstOrDefault() != null) { Button loadMore = mainDiv.Buttons.Where(b => b.ClassName!=null && b.ClassName.Contains("load-more-button")).FirstOrDefault(); if (loadMore != null && loadMore.Exists && loadMore.Enabled) loadMore.ClickNoWait(); var links1 = mainDiv.Links.ToList().Select(l => l.Url).Distinct(); if (links1.Count() > 1000) { foreach (var link in links1) { Console.WriteLine(link); } break; } //mainDiv = browser.Div(Find.ById("video-page-content")); //loadMore = mainDiv.Buttons.Where(b => b.ClassName != null && b.ClassName.Contains("load-more-button")).FirstOrDefault(); } //var links = mainDiv.Links.ToList().Select(l => l.Url).Distinct(); //foreach(var link in links) //{ // Console.WriteLine(link); //} Console.ReadLine(); } }
public void PopulateMobileSpecifications(bool evenId) { Settings.AttachToBrowserTimeOut = 240; Settings.WaitUntilExistsTimeOut = 240; Settings.WaitForCompleteTimeOut = 240; Database.SetInitializer(new CreateDatabaseIfNotExists<MobilesDbContext>()); using (var dbContext = new MobilesDbContext()) { try { List<Product> dbProducts = dbContext.Products.Where(p => p.IsRead == false && ((p.Id%2)==0)==evenId).ToList(); foreach (var dbProduct in dbProducts) { // KillIeProcesses(); string url = dbProduct.Url; using (var browser = new IE(url, true)) { //browser.ShowWindow(NativeMethods.WindowShowStyle.ForceMinimized); //browser.WaitForComplete(); Div specificationsDiv = browser.Div(Find.ById("specs-list")); var productDetails = new ProductDetails(); foreach (Table table in specificationsDiv.Tables) { var specification = new Specification(); Element specificationTypeCell = table.TableRows.First().Children().Where(c => c.TagName.ToUpper() == "TH").First(); if (specificationTypeCell != null && specificationTypeCell.Exists) { specification.Type = specificationTypeCell.Text; } foreach (TableRow tableRow in table.TableRows) { if (tableRow.TableCells.Count > 1) { TableCell keyCell = tableRow.TableCells.FirstOrDefault(); TableCell valueCell = tableRow.TableCells.LastOrDefault(); if (keyCell != null && keyCell.Exists && valueCell != null && valueCell.Exists) { if (keyCell.Links.Count > 0) { var specDetail = new SpecificationDetail(); specDetail.Key = keyCell.Links.First().Text; specDetail.Value = valueCell.Text; specification.Details.Add(specDetail); } else if (specification.Details.Count > 0) { specification.Details.Last().Value = string.Format("{0}{1}", specification.Details .Last(). Value, valueCell.Text); } } } } productDetails.Specifications.Add(specification); dbProduct.IsRead = true; } GenerateProductDetails(dbProduct,productDetails, dbContext); dbContext.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); //throw ex; } } }
public void PopulateMobileImages() { Settings.AttachToBrowserTimeOut = 240; Settings.WaitUntilExistsTimeOut = 240; Settings.WaitForCompleteTimeOut = 240; using (var dbContext = new MobilesDbContext()) { var products = dbContext.Products.Include("Brand").ToList(); var productImageUrls = dbContext.ProductImages.Select(p=>p.ImageUrl).ToList() ; foreach(var product in products) { var productUrl = product.Url; var productName = product.ProductName; var brandName = product.Brand.BrandName; var replaceString = brandName.Replace(" ", "_")+"_"+ productName.Replace(" ", "_"); var picutreUrl = productUrl.Replace(replaceString.ToLower(), replaceString.ToLower() + "-pictures"); KillIeProcesses(); using (var browser = new IE(picutreUrl, true)) { Div pictureDiv = browser.Div(Find.ById("pictures")); var imageUrls = pictureDiv.Images.Select(i => i.Src); foreach(var imageUrl in imageUrls ) { if(productImageUrls.Contains(imageUrl)==false) { dbContext.ProductImages.Add( new ProductImage() { ImageUrl = imageUrl, Product = product } ); } } } dbContext.SaveChanges(); } } }
public void PopulateBrands() { Url = "http://www.gsmarena.com/makers.php3"; using (var browser = new IE(Url,true)) { try { Settings.AttachToBrowserTimeOut = 240; Settings.WaitUntilExistsTimeOut = 240; Settings.WaitForCompleteTimeOut = 240; Thread.Sleep(1000); var shop = new OnlineShoppingModel(); Div allBrandsDiv = browser.Div(Find.ById("mid-col")); Table allBrandTable = allBrandsDiv.Tables.First(); int index = 1; foreach (TableRow brandRow in allBrandTable.TableRows) { IEnumerable<Link> brandLinks = brandRow.Links.Where(l => l.Images.Count > 0); if (brandLinks.Count() > 0) { foreach (Link brandLink in brandLinks) { Image brandImage = brandLink.Images.First(); Link textBrandlink = brandRow.Links.Where(b => b.Url.Contains(brandLink.Url) && b.Images.Count <= 0). First(); string brandText = textBrandlink.Text; string numberOfProducts = brandText.Substring(brandText.IndexOf("(")).Replace("(", "").Replace(")", ""); var brand = new Brand { Id = index, Name = brandImage.Alt, Url = brandLink.Url, NoOfProducts = int.Parse(numberOfProducts), ImageUrl = brandImage.Src }; shop.Brands.Add(brand); index++; } } Database.SetInitializer(new CreateDatabaseIfNotExists<MobilesDbContext>()); using (var dbContext = new MobilesDbContext()) { List<string> brandUrlList = dbContext.Brands.Select(c => c.Url).ToList(); foreach (Brand brand in shop.Brands.Where(c => brandUrlList.Contains(c.Url) == false)) { dbContext.Brands.Add(new DataModels.Brand { BrandName = brand.Name, IsActive = true, AddedDate = DateTime.Now, LastModifiedDate = DateTime.Now, Url = brand.Url, NumberOfProducts = brand.NoOfProducts, ImageUrl = brand.ImageUrl }); } dbContext.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); //throw ex; } } }
public void PopulateBrandPages(IEnumerable<int> brandIdList) { Settings.AttachToBrowserTimeOut = 240; Settings.WaitUntilExistsTimeOut = 240; Settings.WaitForCompleteTimeOut = 240; using (var dbContext = new MobilesDbContext()) { try { List<string> brandPagesList = dbContext.BrandPages.Select(b => b.Url).Distinct().ToList(); List<DataModels.Brand> brands = dbContext.Brands.Where(b => brandIdList.Contains(b.Id)).ToList(); // List<DataModels.Brand> brands = dbContext.Brands.ToList(); foreach (DataModels.Brand brand in brands) { // KillIeProcesses(); if (brandPagesList.Contains(brand.Url).Equals(false)) { brand.BrandPages.Add(new BrandPage { Url = brand.Url, IsInitialPage = true }); } string url = brand.Url; using (var browser = new IE(url,true)) { browser.ShowWindow(NativeMethods.WindowShowStyle.ForceMinimized); browser.WaitForComplete(); Div mainDiv = browser.Div(Find.ById("main")); if (mainDiv.Exists) { Div navigationDiv = mainDiv.Divs.Where(d => d.ClassName != null && d.ClassName.Contains("nav-pages")). FirstOrDefault(); if (navigationDiv != null && navigationDiv.Exists) { List<string> pageLinks = navigationDiv.Links.Select(l=>l.Url).Distinct().ToList(); foreach (var pageLink in pageLinks) { if (brandPagesList.Contains(pageLink).Equals(false)) { brand.BrandPages.Add(new BrandPage { Url = pageLink }); } } } } } dbContext.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); //throw ex; } } }
public void FetchLeetCode() { using (var browser = new IE("https://leetcode.com")) { using (StreamReader sr = new StreamReader(Directory + @"template\solution.html")) { string solutionTemplate = sr.ReadToEnd(); using (StreamReader questionReader = new StreamReader(Directory + @"template\question.html")) { string questionTemplate = questionReader.ReadToEnd(); var toHtml = new IE("http://hilite.me/"); browser.Link(Find.ByClass("btn btn-default")).Click(); browser.TextField(Find.ById("id_login")).SetAttributeValue("value", "*****@*****.**"); //TypeText("*****@*****.**"); browser.TextField(Find.ById("id_password")).SetAttributeValue("value", "Test123"); //.TypeText("Test123"); browser.Button(Find.ByText("Sign In")).Click(); for (int i = 115; i < 300; ++i) { var table = browser.Table(Find.ById("problemList")); var body = table.TableBodies[0]; foreach (var row in body.OwnTableRows) { if (row.Elements != null && row.Elements.Count > 0 && "ac" == row.Elements[1].ClassName) { var cell2 = row.Elements[2] as TableCell; string questionIndex = cell2.Text; if (Int32.Parse(questionIndex) == i) { var cell = row.Elements[3] as TableCell; string questionName = cell.Text; cell.Links[0].Click(); var questionDiv = browser.Div(Find.ByClass("question-content")); string questionContent = ""; for (int j = 0; j < questionDiv.Paras.Count; ++j) { if (!string.IsNullOrEmpty(questionDiv.Paras[j].Text) && questionDiv.Paras[j].Text.StartsWith("<b>Notes:</b>")) { break; } questionContent += "<p>" + questionDiv.Paras[j].Text + "</p>"; } //browser.Links.SelectMany(l => l.Text == "My Submissions"); browser.Links.Filter(l => l.Text == "My Submissions").Where(l => l.Url != "https://leetcode.com/submissions/").First().Click(); //browser.Link(Find.ByText("My Submissions") ). .Click(); browser.WaitForComplete(); var tableResult = browser.Table(Find.ById("result_testcases")); var resultBody = tableResult.TableBodies[0]; string solutionCode = ""; foreach (var resultRow in resultBody.OwnTableRows) { if (resultRow.Elements[3].Text.Contains("Accepted")) { var acceptedCell = resultRow.Elements[3] as TableCell; acceptedCell.Links[0].Click(); var div = browser.Div(Find.ByClass("ace_content")); solutionCode = div.Text; solutionCode = solutionCode.Replace("\r\n\r\n", "\r\n"); break; } } toHtml.TextField(Find.ById("divstyles")).SetAttributeValue("value", "padding:.1em .3em;"); toHtml.TextField(Find.ByName("code")).SetAttributeValue("value", solutionCode); toHtml.SelectList(Find.ByName("lexer")).SelectByValue("cpp"); toHtml.Button(Find.ByValue("Highlight!")).Click(); toHtml.WaitForComplete(3); string questionhtml = questionTemplate.Replace("<%QuestionName%>", questionName).Replace("<%QuestionContent%>", questionContent); string solutonhtml = solutionTemplate.Replace("<%QuestionName%>", questionName).Replace("<%SolutionTemplate%>", toHtml.TextField(Find.ById("html")).Text); solutonhtml = solutonhtml.Replace("margin: 0; line-height: 125%", "margin: 0; line-height: 125%; white-space: pre-wrap;"); string solutionFilename = Directory + "output\\" + questionIndex + ".solution.html"; string questionFileName = Directory + "output\\" + questionIndex + ".question.html"; System.IO.File.WriteAllText(solutionFilename, solutonhtml); System.IO.File.WriteAllText(questionFileName, questionhtml); browser.GoTo("https://leetcode.com/problemset/algorithms/"); } } } } } } } }
static void Main(string[] args) { // Pra não correr o risco do e-mail // já existir para alguma pessoa com o mesmo nome e sobrenome Console.WriteLine("Digite um conjunto de caracteres para garantir a unicidade dos e-mails (não utilize muitos caracteres):"); string emailsUniqueKey = Console.ReadLine(); Console.Clear(); if (emailsUniqueKey.Length > 5) { Console.WriteLine("Qual a parte do \"não utilize muitos caracteres\" você não entendeu?\n\n"); emailsUniqueKey = emailsUniqueKey.Substring(0, 5); } int length; Console.WriteLine("Digite quantas vezes você gostaria de executar a postagem (default 20, para mandar mensagem digite 1):"); if (!Int32.TryParse(Console.ReadLine(), out length)) { Console.Clear(); Console.WriteLine("Vou deixar 20 e fingir que você sabe o que é um inteiro."); length = 20; } else { Console.Clear(); } // Para que as mensagens não fiquem repetitivas, elas devem ser digitadas e adicionadas uma a uma string mensagem = string.Empty; if (length == 1) { Console.WriteLine("Digite sua mensagem de carinho:"); mensagem = Console.ReadLine(); Console.Clear(); } Console.WriteLine("\n\n ------------- Iniciando -------------"); Console.WriteLine("\n\n Espero que você tenha Internet Explorer instalado... "); using (var browser = new IE("https://foursquare.com/")) { for (int seed = 0; seed < length; seed++) { // Abrindo formulário de cadastro browser.Link(Find.ById("signupButton")).Click(); browser.Div(Find.ById("signupButtonMenu")).Link(Find.ByClass("emailSignup")).Click(); // Preenchendo o formulário Random rnd = new Random(); string firstName = names[rnd.Next(501)]; string lastName = names[rnd.Next(501)]; string email = String.Format("{0}_{1}_{3}{2}@mailinator.com", firstName.ToLowerInvariant(), lastName.ToLowerInvariant(), seed, emailsUniqueKey); int day = rnd.Next(1, 29); // Até 28, pra não ter problema com fevereiro int month = rnd.Next(1, 13); browser.TextField(Find.ById("inputEmail")).Value = email; browser.TextField(Find.ById("inputPassword")).Value = PASSWORD; browser.TextField(Find.ById("inputFirstName")).Value = firstName; browser.TextField(Find.ById("inputLastName")).Value = lastName; browser.TextField(Find.ById("inputBirthDate")).Value = day < 10 ? "0" + day : day.ToString(); browser.TextField(Find.ById("inputBirthMonth")).Value = month < 10 ? "0" + month : month.ToString(); browser.TextField(Find.ById("inputBirthYear")).Value = rnd.Next(1950, 2000).ToString(); // Clica em Sing Up browser.Button(Find.ById("signupButton")).Click(); // Clica em Skip browser.Button(Find.ById("finishedTastesButton")).Click(); // Clica em Finished browser.Button(Find.ById("closeButton")).Click(); // Preenche o campo de pesquisa browser.TextField(Find.ById("headerBarSearch")).Value = "La Fiesta"; // Vai para o perfil do la fiesta browser.GoTo("https://foursquare.com/v/la-fiesta/536c3ea0498e38181e296a5f"); // Clica em dislike - por não conseguir achar a classe certa, temos que fazer foreach var actionBar = browser.Div(Find.ById("actionBar")); foreach (var div in actionBar.Divs) { if (div.ClassName.Contains("dislike")) { div.Click(); break; } } // Adiciona mensagem if (length == 1) { // Escreve o texto foreach (var div in browser.Div(Find.ByClass("addTipBlock")).Divs) { if (div.ClassName.Contains("addTipArea")) { foreach (var item in div.Elements) { if (item.ClassName.Contains("formStyle")) { ((TextField)item).Value = mensagem; break; } } break; } } // Clica em publicar foreach (var button in browser.Div(Find.ByClass("buttonArea")).Buttons) { if (button.ClassName.Contains("greenButton")) { button.Click(); break; } } } // Faz logoff browser.Link(Find.ById("logoutLink")).Click(); Console.WriteLine("Execução finalizada ~ " + (seed + 1)); } Console.WriteLine("\n\n ------------- Finalizado -------------"); } }
public static string FillData(IE ie, HControl control, string data) { int i = 0; while (i < Loop) { i++; try { switch (control.Control.ToLower()) { case ControlType.AHref: ie.Link(GetControl(ie, control)).Click(); break; case ControlType.AHrefNoText: ie.GoTo(control.Value); break; case ControlType.Button: ie.Button(GetControl(ie, control)).Click(); break; case ControlType.Div: ie.Div(GetControl(ie, control)).Click(); break; case ControlType.TextArea: ie.TextField(GetControl(ie, control)).Value = data; break; case ControlType.TextBox: ie.TextField(GetControl(ie, control)).Value = data; break; } ie.WaitForComplete(); return string.Empty; } catch (Exception ex) { if (i == Loop) { return ex.Message; } Thread.Sleep(60000); } } return string.Empty; }
public static WatiN.Core.Div GetDiv(IE ie, HControl control) { switch (control.Attribute.ToLower()) { case AttributeType.Id: { Div div = ie.Div(Find.ById(control.Value)); if (div.Exists) return div; return null; } case AttributeType.Name: { Div div = ie.Div(Find.ByName(control.Value)); if (div.Exists) return div; return null; } case AttributeType.Class: { Div div = ie.Div(Find.ByClass(control.Value)); if (div.Exists) return div; return null; } case AttributeType.Text: { foreach (WatiN.Core.Div bt in ie.Divs) { if (bt.Text == control.Value) return bt; } return null; } default: { foreach (WatiN.Core.Div bt in ie.Divs) { if (bt.Name == control.Value) return bt; } return null; } } }
public static object FindControlInBrowserByID(IE ie, string strID, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.ById(strID)); Assert.IsTrue(sp.Exists, "Could not Find: " + strID); return sp; } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.ById(strID)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strID); return lnk; } else if (ctrl == Enumerators.ControlType.Frame) { Frame iFrame = ie.Frame(Find.ById(strID)); return iFrame; } else if (ctrl == Enumerators.ControlType.Image) { Image img = ie.Image(Find.ById(strID)); Assert.IsTrue(img.Exists, "Could not Find: " + strID); return img; } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.ById(strID)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strID); return tCell; } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.ById(strID)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strID); return tbl; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.ById(strID)); Assert.IsTrue(row.Exists, "Could not Find: " + strID); return row; } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.ById(strID)); Assert.IsTrue(chk.Exists, "Could not Find: " + strID); return chk; } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.ById(strID)); Assert.IsTrue(btn.Exists, "Could not Find: " + strID); return btn; } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.ById(strID)); Assert.IsTrue(txt.Exists, "Could not Find: " + strID); return txt; } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.ById(strID)); Assert.IsTrue(sList.Exists, "Could not Find: " + strID); return sList; } else if (ctrl == Enumerators.ControlType.Div) { Div division = ie.Div(Find.ById(strID)); Assert.IsTrue(division.Exists, "Could not Find: " + strID); return division; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow tRow = ie.TableRow(Find.ById(strID)); Assert.IsTrue(tRow.Exists, "Could not Find: " + strID); return tRow; } else if (ctrl == Enumerators.ControlType.FileUpload) { FileUpload fileUpload = ie.FileUpload(Find.ById(strID)); Assert.IsTrue(fileUpload.Exists, "Could not find: " + strID); return fileUpload; } else { return null; } }
public static object FindControlInBrowserByCustom(IE ie, string strCustomAttribute, string strToFind, Enumerators.ControlType ctrl) { if (ctrl == Enumerators.ControlType.Span) { Span sp = ie.Span(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sp.Exists, "Could not Find: " + strToFind); return sp; } else if (ctrl == Enumerators.ControlType.Link) { Link lnk = ie.Link(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(lnk.Exists, "Could not Find: " + strToFind); return lnk; } else if (ctrl == Enumerators.ControlType.Frame) { Frame frame = ie.Frame(Find.By(strCustomAttribute, strToFind)); Assert.AreEqual(frame.Name, strToFind); return frame; } else if (ctrl == Enumerators.ControlType.Image) { Image img; if (strCustomAttribute == "src") { img = ie.Image(Find.BySrc(strToFind)); } else { img = ie.Image(Find.By(strCustomAttribute, strToFind)); } Assert.IsTrue(img.Exists, "Could not Find: " + strToFind); return img; } else if (ctrl == Enumerators.ControlType.TableCell) { TableCell tCell = ie.TableCell(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tCell.Exists, "Could not Find: " + strToFind); return tCell; } else if (ctrl == Enumerators.ControlType.Table) { Table tbl = ie.Table(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(tbl.Exists, "Could not Find: " + strToFind); return tbl; } else if (ctrl == Enumerators.ControlType.TableRow) { TableRow row = ie.TableRow(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(row.Exists, "Could not Find: " + strToFind); return row; } else if (ctrl == Enumerators.ControlType.CheckBox) { CheckBox chk = ie.CheckBox(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(chk.Exists, "Could not Find: " + strToFind); return chk; } else if (ctrl == Enumerators.ControlType.Button) { Button btn = ie.Button(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(btn.Exists, "Could not Find: " + strToFind); return btn; } else if (ctrl == Enumerators.ControlType.TextField) { TextField txt = ie.TextField(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(txt.Exists, "Could not Find: " + strToFind); return txt; } else if (ctrl == Enumerators.ControlType.SelectList) { SelectList sList = ie.SelectList(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(sList.Exists, "Could not Find: " + strToFind); return sList; } else if (ctrl == Enumerators.ControlType.Div) { Div div = ie.Div(Find.By(strCustomAttribute, strToFind)); Assert.IsTrue(div.Exists, "Could not Find: " + strToFind); return div; } else { return null; } }
private static void AddPreSale(Model.ManheimEntities manheimModel, Model.Auction auctionEntity, DateTime saleDate, WC.TableCellCollection tds, string vin, WC.IE vehicleInfoIE) { var rightContent = vehicleInfoIE.Div("rightContent"); #region Vehicle #region Grade var grade = 0.0; var lastColumn = rightContent.Div(WC.Find.ByClass("lastColumn")); if (lastColumn.Exists) { var gradeLink = lastColumn.Link(WC.Find.ByText(new Regex("Grade"))); if (gradeLink.Exists) { double.TryParse(Regex.Replace(gradeLink.Text, @"[^\d.]", ""), out grade); } } #endregion var mmrElement = vehicleInfoIE.Link("mmrHover"); int mmrPrice = 0; if (mmrElement.Exists) { int.TryParse(mmrElement.Text, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, NumberFormatInfo.CurrentInfo, out mmrPrice); } var div = vehicleInfoIE.Div(new Regex("vdpTab_detail-1")); var table = div.Tables.First(); if (table != null) { var vehicleEntity = manheimModel.Vehicles.SingleOrDefault(v => v.VIN == vin); if (vehicleEntity == null) { vehicleEntity = SetVehicle(table); vehicleEntity.Grade = grade; manheimModel.Vehicles.Add(vehicleEntity); } else { UpdateVehicle(vehicleEntity, table); } vehicleEntity.MMR = mmrPrice; manheimModel.SaveChanges(); #endregion #region Seller var sellerElement = rightContent.Div(WC.Find.ByClass("firstColumn")).ElementWithTag("li", WC.Find.First()); var sellerName = sellerElement.Exists ? sellerElement.Text : ""; var sellerEntity = manheimModel.Sellers.SingleOrDefault(s => s.Name == sellerName); if (sellerEntity == null) { sellerEntity = new Model.Seller() { Name = sellerName }; manheimModel.Sellers.Add(sellerEntity); manheimModel.SaveChanges(); } #endregion #region PreSale var preSale = new Model.PreSale() { Ln = int.Parse(tds[0].Text.Split('-')[0]), Run = int.Parse(tds[0].Text.Split('-')[1]), SaleDate = saleDate }; lock (auctionEntity) { preSale.Vehicle = vehicleEntity; preSale.Auction = auctionEntity; preSale.Seller = sellerEntity; manheimModel.PreSales.Add(preSale); } #endregion manheimModel.SaveChanges(); } }