Пример #1
0
        public static string GetTextFromDDL(TypesOfElementsPaths pathType, string pathValue, IWebDriver driver)
        {
            switch (pathType)
            {
            case TypesOfElementsPaths.Name:
            {
                return(new SelectElement(driver.FindElement(By.Name(pathValue)))
                       .AllSelectedOptions.SingleOrDefault()?.Text);
            }

            case TypesOfElementsPaths.Id:
            {
                return(new SelectElement(driver.FindElement(By.Id(pathValue)))
                       .AllSelectedOptions.SingleOrDefault()?.Text);
            }

            case TypesOfElementsPaths.XPath:
            {
                return(new SelectElement(driver.FindElement(By.XPath(pathValue)))
                       .AllSelectedOptions.SingleOrDefault()?.Text);
            }

            case TypesOfElementsPaths.CssSelector:
            {
                return(new SelectElement(driver.FindElement(By.CssSelector(pathValue)))
                       .AllSelectedOptions.SingleOrDefault()?.Text);
            }
            }
            throw new NoSuchElementException($"No Element With Identifer Called {pathValue} was Found!");
        }
        public static void Submit(TypesOfElementsPaths pathType, string pathValue, IWebDriver driver)
        {
            switch (pathType)
            {
            case TypesOfElementsPaths.Name:
            {
                driver.FindElement(By.Name(pathValue)).Submit();
                break;
            }

            case TypesOfElementsPaths.Id:
            {
                driver.FindElement(By.Id(pathValue)).Submit();
                break;
            }

            case TypesOfElementsPaths.XPath:
            {
                driver.FindElement(By.XPath(pathValue)).Submit();
                break;
            }

            case TypesOfElementsPaths.CssSelector:
            {
                driver.FindElement(By.CssSelector(pathValue)).Submit();
                break;
            }
            }
        }
Пример #3
0
        public static string GetTextFromValueAttribute(TypesOfElementsPaths pathType, string pathValue, IWebDriver driver)
        {
            switch (pathType)
            {
            case TypesOfElementsPaths.Name:
            {
                return(driver.FindElement(By.Name(pathValue)).GetAttribute("value"));
            }

            case TypesOfElementsPaths.Id:
            {
                return(driver.FindElement(By.Id(pathValue)).GetAttribute("value"));
            }

            case TypesOfElementsPaths.XPath:
            {
                return(driver.FindElement(By.XPath(pathValue)).GetAttribute("value"));
            }

            case TypesOfElementsPaths.CssSelector:
            {
                return(driver.FindElement(By.CssSelector(pathValue)).GetAttribute("value"));
            }
            }
            throw new Exception($"No Element With Identifer Called {pathValue} was Found!");
        }
        public static void SelectOption(TypesOfElementsPaths pathType, string pathValue, string value, IWebDriver driver)
        {
            switch (pathType)
            {
            case TypesOfElementsPaths.Name:
            {
                new SelectElement(driver.FindElement(By.Name(pathValue))).SelectByText(value);
                break;
            }

            case TypesOfElementsPaths.Id:
            {
                new SelectElement(driver.FindElement(By.Id(pathValue))).SelectByText(value);
                break;
            }

            case TypesOfElementsPaths.XPath:
            {
                new SelectElement(driver.FindElement(By.XPath(pathValue))).SelectByText(value);
                break;
            }

            case TypesOfElementsPaths.CssSelector:
            {
                new SelectElement(driver.FindElement(By.CssSelector(pathValue))).SelectByText(value);
                break;
            }
            }
        }