private static void AddSpecificProducts(Products products) { List <string> ProductNames = GetProductNames(products); Actions actions = new Actions(Driver); IWebElement AddToCartButton; IWebElement ContinueShoppingButton; ReadOnlyCollection <IWebElement> PotentialProducts = Driver.FindElements(By.ClassName("product-container"), 5); foreach (IWebElement product in PotentialProducts) { if (!product.Displayed) { continue; } IWebElement NameElement = product.FindElement(By.ClassName("product-name")); if (ProductNames.Contains(NameElement.Text)) // Ideally, I'd compare a product SKU or UPC# to avoid changes to product names. { actions.MoveToElement(product); AddToCartButton = product.FindElement(By.CssSelector("[title=\"Add to cart\"]")); if (!AddToCartButton.Displayed) { continue; } actions.MoveToElement(AddToCartButton); Thread.Sleep(250); AddToCartButton.Click(); ContinueShoppingButton = Driver.FindElement(By.ClassName("continue"), 2, FindModifier.IS_VISIBLE); ContinueShoppingButton.Click(); } } }
internal static void AddAllProducts() { IWebElement ContinueShoppingButton; IReadOnlyCollection <IWebElement> AddToCartButtonCollection = Driver.FindElements(By.CssSelector("[title=\"Add to cart\"]"), 3); Actions actions = new Actions(Driver); foreach (IWebElement AddToCartButton in AddToCartButtonCollection) { if (!AddToCartButton.Displayed) { continue; } actions.MoveToElement(AddToCartButton); WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(3)); IWebElement NewAddToCartButton = wait.Until(ExpectedConditions.ElementToBeClickable(AddToCartButton)); NewAddToCartButton.Click(); ContinueShoppingButton = Driver.FindElement(By.ClassName("continue"), 2, FindModifier.IS_VISIBLE); ContinueShoppingButton.Click(); Thread.Sleep(300); } }
public void ValidateProductsChosen() { Helper.ScrollToSeeTheRightButton(_driver, FirstBlouse); FirstBlouse.Click(); _driver.SwitchTo().Frame(_driver.FindElement(By.XPath("//iframe[@src='http://automationpractice.com/index.php?id_product=2&controller=product&content_only=1']"))); FirstBlouseBigImage.Click(); Helper.ScrollToSeeTheRightButton(_driver, AddToCartButton); AddToCartButton.Click(); Thread.Sleep(2000); ContinueShoppingButton.Click(); Actions actions = new Actions(_driver); IWebElement target = DressesTab; actions.MoveToElement(target).Perform(); SummerDressesSubMenu.Click(); Helper.ScrollToSeeTheRightButton(_driver, ThirdDress); ThirdDress.Click(); _driver.SwitchTo().Frame(_driver.FindElement(By.XPath("//iframe[@src='http://automationpractice.com/index.php?id_product=7&controller=product&content_only=1']"))); ThirdDressBigImage.Click(); Helper.ScrollToSeeTheRightButton(_driver, AddToCartButton); AddToCartButton.Click(); Thread.Sleep(3000); ContinueShoppingButton.Click(); Helper.ScrollToSeeTheRightButton(_driver, TshirtsTab); TshirtsTab.Click(); Helper.ScrollToSeeTheRightButton(_driver, FirstTshirt); FirstTshirt.Click(); _driver.SwitchTo().Frame(_driver.FindElement(By.XPath("//iframe[@src='http://automationpractice.com/index.php?id_product=1&controller=product&content_only=1']"))); FirstTshirtBigImage.Click(); Helper.ScrollToSeeTheRightButton(_driver, AddToCartButton); AddToCartButton.Click(); Thread.Sleep(3000); CheckoutButton.Click(); Helper.ScrollToSeeTheRightButton(_driver, CartButton); CartButton.Click(); }
//Buttons public void ClickContinueShoppingButton() { ContinueShoppingButton.Click(); }