/// <summary> /// Method to get a list of products /// </summary> /// <param name="amount">The amount of products we want</param>list /// <returns>List with products</returns> public List <Product> GetListOfProducts(int amount) { List <Product> ProductsList = new List <Product>(); //We iterate through every product and transform them into Product objects foreach (IWebElement aux in GetRawDataOfProducts(5)) { //Getting the raw string where the price is located String RawPriceText = aux.FindElement(By.CssSelector(Strings.RAW_PRICE_TEXT)).Text; //Getting rid off the currency List <String> ValuesOfText = Regex.Split(RawPriceText, @Strings.PRICE_REGEX) .Where(a => a != "." && a.Trim() != "").ToList(); Decimal priceAux = Decimal.Parse(ValuesOfText[0].Trim()); //Getting the raw string where the name is located String NameAux = aux.FindElement(By.CssSelector(Strings.RAW_NAME_TEXT)).Text; //If shipping has a value, we will updated. Otherwise, we will add 0 Decimal shippingAux = 0; /*If the item has a shipping text, and it is * indeed a valid price (no free shipping text or any other label) * we will add it as shipping cost */ if (aux.FindElements(By.CssSelector(Strings.RAW_LOGICIST_COST_TEXT)).Count > 0 && aux.FindElement(By.CssSelector(Strings.RAW_LOGICIST_COST_TEXT)).Text.Any(char.IsDigit)) { String RawShippingText = aux.FindElement(By.CssSelector(Strings.RAW_LOGICIST_COST_TEXT)).Text; //Getting rid off the currency List <String> ValuesOfShipping = Regex.Split(RawShippingText, @Strings.PRICE_REGEX) .Where(a => a != "." && a.Trim() != "").ToList(); //Adding to the list the price shippingAux = Decimal.Parse(ValuesOfShipping[0].Trim()); } //Creating new product Product newProduct = DomainFactory.CreateProduct (NameAux, priceAux, shippingAux); //adding the product to the list ProductsList.Add(newProduct); } return(ProductsList); }