static void Main(string[] args)
        {
            using (var driver = new OpenQA.Selenium.Chrome.ChromeDriver())
            {
                driver.Navigate().GoToUrl("https://www.bing.com/");
                driver.FindElementById("sb_form_q").SendKeys("Selenium WebDriver");
                driver.FindElementById("sb_form_go").Click();

                Console.WriteLine("OK");
                Console.ReadKey(intercept: true);
            }
        }
        private object FindElement(OpenQA.Selenium.Chrome.ChromeDriver seleniumInstance, string searchParameter)
        {
            object element = null;

            switch (v_SeleniumSearchType)
            {
            case "Find Element By XPath":
                element = seleniumInstance.FindElementByXPath(searchParameter);
                break;

            case "Find Element By ID":
                element = seleniumInstance.FindElementById(searchParameter);
                break;

            case "Find Element By Name":
                element = seleniumInstance.FindElementByName(searchParameter);
                break;

            case "Find Element By Tag Name":
                element = seleniumInstance.FindElementByTagName(searchParameter);
                break;

            case "Find Element By Class Name":
                element = seleniumInstance.FindElementByClassName(searchParameter);
                break;

            case "Find Element By CSS Selector":
                element = seleniumInstance.FindElementByCssSelector(searchParameter);
                break;

            case "Find Elements By XPath":
                element = seleniumInstance.FindElementsByXPath(searchParameter).ToList();
                break;

            case "Find Elements By ID":
                element = seleniumInstance.FindElementsById(searchParameter).ToList();
                break;

            case "Find Elements By Name":
                element = seleniumInstance.FindElementsByName(searchParameter).ToList();
                break;

            case "Find Elements By Tag Name":
                element = seleniumInstance.FindElementsByTagName(searchParameter).ToList();
                break;

            case "Find Elements By Class Name":
                element = seleniumInstance.FindElementsByClassName(searchParameter).ToList();
                break;

            case "Find Elements By CSS Selector":
                element = seleniumInstance.FindElementsByCssSelector(searchParameter).ToList();
                break;

            default:
                throw new Exception("Search Type was not found");
            }

            return(element);
        }
Ejemplo n.º 3
0
        public void TestNewCode(string UrlPath)
        {
            using (var driver = new OpenQA.Selenium.Chrome.ChromeDriver())
            {
                UrlPath = "https://privatepath.co.uk/browse/" + UrlPath;

                driver.Navigate().GoToUrl(UrlPath);

                System.Threading.Thread.Sleep(15000);
                IWebElement PageButton = driver.FindElementById("opsbar-opsbar-transitions");
                var         myButton   = PageButton.FindElement(By.Id("action_id_91"));
                myButton.Click();
                IWebElement PageButton2 = driver.FindElementByClassName("buttons");
                var         myButton2   = PageButton2.FindElement(By.ClassName("aui-button"));
                myButton2.Click();
                IWebElement PageElements = driver.FindElement(By.ClassName("item-attachments"));
                var         myAttach     = PageElements.FindElements(By.TagName("li"));
                foreach (var item in myAttach)
                {
                    Console.WriteLine(item.Text);
                    Console.WriteLine(item.GetAttribute("data-downloadurl").ToString());
                    if (item.GetAttribute("data-downloadurl").ToString().StartsWith("application/zip:"))
                    {
                        item.Click();
                        System.Threading.Thread.Sleep(1000);
                        Console.WriteLine("Downloading File...");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var chrome = new OpenQA.Selenium.Chrome.ChromeDriver {
                Url = "http://www.google.com"
            };

            chrome.FindElementById("lst-ib").SendKeys("muratoner.net");
            chrome.FindElementByClassName("lsb").Click();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            using (var driver = new OpenQA.Selenium.Chrome.ChromeDriver())
            {
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                driver.Navigate().GoToUrl("https://www.bing.com/");
                driver.FindElementById("sb_form_q").SendKeys("Selenium WebDriver");
                driver.FindElementByClassName("search").Click();

                Console.WriteLine("OK");
                Console.ReadKey(intercept: true);
            }
        }
Ejemplo n.º 6
0
        public void RunActions(List <Action> actions)
        {
            var missedActions = new List <Action>();

            foreach (var action in actions)
            {
                try
                {
                    if (action.ActionType == ActionType.Wait)
                    {
                        Thread.Sleep(TimeSpan.Parse($"{action.InputData}"));
                        continue;
                    }

                    if (action.ActionType != ActionType.Navigate)
                    {
                        IWebElement element = null;

                        if (!string.IsNullOrEmpty(action.ObjectID))
                        {
                            element = driver.FindElementById(action.ObjectID);
                        }
                        else if (!string.IsNullOrEmpty(action.Label))
                        {
                            element = driver.FindElementByClassName(action.Label);
                        }

                        Console.WriteLine($"Running {action.ActionType} {action.InputData} {action.Label} {action.ObjectID}");

                        switch (action.ActionType)
                        {
                        case ActionType.ClearText:
                            int n = 18;
                            while (n > 0)
                            {
                                element.SendKeys(Keys.Backspace);
                                n--;
                            }
                            break;

                        case ActionType.Click:
                            //element.Click();
                            Actions webAction = new Actions(driver);
                            webAction.MoveToElement(element).Click().Perform();
                            break;

                        case ActionType.InputText:
                        case ActionType.InputUsername:
                        case ActionType.InputPassword:
                            element.SendKeys(action.InputData);
                            break;

                        case ActionType.EnterPush:
                            element.SendKeys(Keys.Enter);
                            break;
                        }
                    }
                    else if (action.ActionType == ActionType.Navigate)
                    {
                        driver.Url = action.InputData;
                        driver.Navigate();
                    }
                }
                catch (Exception ex)
                {
                    if (action.Optional)
                    {
                        Console.WriteLine($"ERROR : {action.InputData} {action.ActionType} {action.Label} {action.ObjectID} action missed");
                        missedActions.Add(action);
                        continue;
                    }

                    throw ex;
                }
            }

            if (missedActions.Any())
            {
                string errorMessage = "";
                foreach (var action in missedActions)
                {
                    errorMessage += $"Exception on {action.Label} {action.ObjectID}";
                }

                throw new Exception(errorMessage);
            }
        }