public static void DriverInitialize()
        {
            _driver = new OpenQA.Selenium.Chrome.ChromeDriver();

            _driver.Manage().Window.Maximize();
            _driver.Manage().Timeouts().ImplicitWait = System.TimeSpan.FromSeconds(30);
        }
Ejemplo n.º 2
0
        public void WhenDepartureEqualDestination()
        {
            IWebDriver browser;
            bool       passTest = false;

            browser = new OpenQA.Selenium.Chrome.ChromeDriver();
            browser.Manage().Window.Maximize();
            browser.Navigate().GoToUrl("http://avia.321.by/");
            ClassPageFactory pageObject = new ClassPageFactory(browser);

            pageObject.Place_from.Clear();
            pageObject.Place_from.SendKeys("Минск");
            System.Threading.Thread.Sleep(1000);
            pageObject.Place_from.SendKeys(OpenQA.Selenium.Keys.Enter);

            pageObject.DepartureDate_first.Click();
            System.Threading.Thread.Sleep(1000);
            pageObject.Calendar_datefirst.Click();

            pageObject.Place_to.Clear();
            pageObject.Place_to.SendKeys("Минск");
            System.Threading.Thread.Sleep(1000);
            pageObject.Place_to.SendKeys(OpenQA.Selenium.Keys.Enter);

            pageObject.DepartureDate_second.Click();
            System.Threading.Thread.Sleep(1000);
            pageObject.Calendar_datesecond.Click();

            pageObject.SearchButton.Click();
            System.Threading.Thread.Sleep(5000);

            passTest = pageObject.WarningWindow.Displayed;
            Assert.IsTrue(passTest, "Departure City Equal Destination City! Input Error!");
        }
Ejemplo n.º 3
0
        public override void RunCommand(object sender)
        {
            var engine     = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var driverPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Resources");

            OpenQA.Selenium.Chrome.ChromeDriverService driverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(driverPath);

            var newSeleniumSession = new OpenQA.Selenium.Chrome.ChromeDriver(driverService, new OpenQA.Selenium.Chrome.ChromeOptions());

            var instanceName = v_InstanceName.ConvertToUserVariable(sender);

            engine.AddAppInstance(instanceName, newSeleniumSession);


            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, newSeleniumSession);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                newSeleniumSession.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
Ejemplo n.º 4
0
        public void GivenUserIsOnMainPage()
        {
            IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(@"D:\1\");

            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://loving-hermann-e2094b.netlify.app/index.html");
            signUpPage = new SignUpPage(driver);
        }
Ejemplo n.º 5
0
        public static List <string> getter()
        {
            IWebDriver Browser = new OpenQA.Selenium.Chrome.ChromeDriver();

            Browser.Manage().Window.Maximize();
            Browser.Navigate().GoToUrl("http://apip.gov.gn/?q=content/annonces-l%C3%A9gales");
            Regex RCCM = new Regex("\\d{3}[.]\\d{3}[A-Z]|\\d{6}[A-Z]|\\d{6}|\\d{3}[.]\\d{3}");
            Regex Date = new Regex("\\d{2}[/]\\d{2}[/]\\d{4}|\\d{1,2}\\s\\w{3,10}[,]\\s\\d{4}");

            List <string> output = new List <string>();

            try
            {
                bool flag = true;
                while (true)
                {
                    if (flag)
                    {
                        flag = !flag;

                        ReadOnlyCollection <IWebElement> list      = Browser.FindElements(By.ClassName("views-field-title"));
                        ReadOnlyCollection <IWebElement> listDates = Browser.FindElements(By.ClassName("views-field-body-1"));

                        for (int i = 0; i < list.Count; i++)
                        {
                            string combine = "";
                            string date    = listDates[i].Text.ToString();
                            combine += list[i].Text.ToString() + "|";
                            Match  match = RCCM.Match(date);
                            string tmp   = match.Value.ToString();
                            combine += tmp + "|";
                            match    = Date.Match(date);
                            tmp      = match.Value.ToString();
                            combine += tmp;
                            output.Add(combine);
                        }
                    }
                    else
                    {
                        flag = !flag;
                    }



                    IWebElement element = Browser.FindElement(By.XPath("//A[@title='Go to next page'][text()='next ›']"));

                    Actions actions = new Actions(Browser);

                    actions.MoveToElement(element);
                    actions.Click().Perform();
                }
            }
            catch
            {
            }
            Browser.Quit();
            return(output);
        }
        public IWebDriver NavigatetoApp(string url)
        {
            IWebDriver myChrome;

            myChrome = new OpenQA.Selenium.Chrome.ChromeDriver();
            myChrome.Navigate().GoToUrl(url);
            myChrome.Manage().Window.Maximize();
            return(myChrome);
        }
Ejemplo n.º 7
0
        private void SeleniumVertifyCode(Uri uri)
        {
            var options = new OpenQA.Selenium.Chrome.ChromeOptions();

            options.AddArgument("-headless");
            options.AddArgument("log-level=3");
            using IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(options);
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl(uri);
            driver.Manage().Cookies.AddCookie(new Cookie("QCCSESSID", Cookie, ".qcc.com", "/", null));
            driver.Navigate().GoToUrl(uri);
            driver.ExecuteJavaScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})");
            var slide           = driver.FindElement(By.CssSelector("#nc_1_n1z"));
            var verifyContainer = driver.FindElement(By.CssSelector(".nc-lang-cnt"));
            var width           = verifyContainer.Size.Width;
            var action          = new Actions(driver);

            action.ClickAndHold(slide).Perform();
            Random    random    = new Random();
            int       offset    = 0;
            const int minOffset = 10;
            const int maxOffset = 30;

            while (width > offset)
            {
                offset += random.Next(minOffset, maxOffset);
                action.MoveByOffset(offset, 0).Perform();
                var code = driver.FindElement(By.CssSelector(".nc-lang-cnt")).Text;
                if (code.Contains("验证通过"))
                {
                    break;
                }
                System.Threading.Thread.Sleep(offset * minOffset);
            }
            //截图测试
            //Screenshot screenShotFile = ((ITakesScreenshot)driver).GetScreenshot();
            //string img_url = Environment.CurrentDirectory + "\\test.png";
            //screenShotFile.SaveAsFile(img_url, ScreenshotImageFormat.Png);
            action.Click(driver.FindElement(By.CssSelector("#verify"))).Perform();
            driver.Quit();
        }
Ejemplo n.º 8
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.º 9
0
        public IWebDriver GetDriver()
        {
            var path = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            path = path.Replace("file:\\", "");
            path = path.Replace("file:/", "/");

            var driver = new OpenQA.Selenium.Chrome.ChromeDriver(path);

            driver.Manage().Window.Maximize();

            return(driver);
        }
        public void SelectOptnTest()
        {
            IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(@"C:\Users\Vinod Kumar\Documents\Visual Studio 2015\Projects\ToolsQA\packages");

            driver.Manage().Window.Maximize();
            driver.Url = "https://accounts.google.com/signin/v2/sl/pwd?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=AddSession&cid=0&navigationDirection=forward";
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
            driver.FindElement(By.XPath("//input[@id='identifierId']")).Click();
            IWebElement ele = driver.FindElement(By.XPath("//input[@id='identifierId']"));

            File.ReadAllText(@"ToolsQA\");
            //driver.FindElement(By.XPath("//input[@id='identifierId']")).SendKeys("vinodkumarvinni");
            driver.FindElement(By.Id("next")).Click();

            //driver.Navigate().GoToUrl("http://toolsqa.wpengine.com/automation-practice-form/");
            //driver.Manage().Timeouts().ImplicitWait=TimeSpan.FromSeconds(20);
            //SelectElement oSelection = new SelectElement(driver.FindElement(By.Name("selenium_commands")));
            //oSelection.SelectByIndex(0);
            //Thread.Sleep(2000);
            //oSelection.DeselectByIndex(0);
            //Thread.Sleep(2000);
            //oSelection.SelectByText("Navigation Commands");
            //Thread.Sleep(2000);
            //oSelection.DeselectByText("Navigation Commands");
            //Thread.Sleep(2000);
            //IList<IWebElement> selectOptions = oSelection.Options;
            //int lstSelect = selectOptions.Count;
            //for(int i=0;i<lstSelect;i++)
            //{
            //    string lstOptions = oSelection.Options.ElementAt(i).Text;
            //    Console.WriteLine("Select Options "+lstOptions);
            //    oSelection.SelectByIndex(i);
            //    //Thread.Sleep(5000);
            //}
            //oSelection.DeselectAll();
            driver.Quit();
        }
Ejemplo n.º 11
0
        private void Check_Click(object sender, RoutedEventArgs e)
        {
            if (WallmartCheckBox.IsChecked == false &&
                SearsCheckBox.IsChecked == false &&
                TigerdirectCheckBox.IsChecked == false &&
                OverstockCheckBox.IsChecked == false &&
                NeweggCheckBox.IsChecked == false &&
                ToysrusCheckBox.IsChecked == false &&
                BestbuyCheckBox.IsChecked == false)
            {
                MessageBox.Show("Choose what sites you whant to check", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (Store.Users.Count > 0)
            {
                ProgressBar.Value   = 0;
                ProgressBar.Maximum = Store.Users.Count;
                IWebDriver browser = new OpenQA.Selenium.Chrome.ChromeDriver();
                browser.Manage().Cookies.DeleteAllCookies();
                browser.Manage().Window.Maximize();
                foreach (var user in Store.Users)
                {
                    if (user.Login != "" && user.Password != "")
                    {
                        CheckSelected(user, browser);
                    }
                    ProgressBar.Value += 1;
                }
                browser.Quit();
                Store.ResultMessage(ProgressBar.Value.ToString());
            }
            else
            {
                MessageBox.Show("You must download users", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 12
0
        static void Main()
        {
            //System.setProperty("webdriver.chrome.driver", "/usr/local/bin/ChromeDriver/chromedriver");
            IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver();

            // WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            driver.Manage().Window.Maximize();

            //   driver.Manage().Timeouts().ImplicitWait.Milliseconds.(10, TimeUnit.SECONDS);
            driver.Url = "http://youtube.com";
            driver.FindElement(By.CssSelector("#search")).SendKeys("Денчик грудные");
            driver.FindElement(By.CssSelector("#search-icon-legacy > yt-icon")).Click();
            Thread.Sleep(10000);
            driver.Close();
        }
Ejemplo n.º 13
0
        public void Main()
        {
            IWebDriver browser;

            browser = new OpenQA.Selenium.Chrome.ChromeDriver();
            browser.Manage().Window.Maximize();
            browser.Navigate().GoToUrl("https://www.anywayanyday.com/en/");

            IWebElement cityFrom = browser.FindElement(By.ClassName("awadWidget-aviaInput"));

            cityFrom.SendKeys("Moscow" + OpenQA.Selenium.Keys.Enter);
            System.Threading.Thread.Sleep(2000);

            IWebElement cityTo = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div/div/div/div[2]/div[3]/div/div[2]/div/input"));

            cityTo.SendKeys("San Francisco" + OpenQA.Selenium.Keys.Enter);

            IWebElement date = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div/div/div/div[2]/div[3]/div/div[4]/div/div[1]"));

            date.Click();
            System.Threading.Thread.Sleep(2000);

            IWebElement datePick = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div/div/div/div[2]/div[3]/div/div[5]/div/div[2]/div[2]/table/tbody/tr[5]/td[4]/span"));

            datePick.Click();
            System.Threading.Thread.Sleep(2000);

            IWebElement returnFlight = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div[1]/div/div/div[2]/div[4]/div[1]/div[1]"));

            returnFlight.Click();
            System.Threading.Thread.Sleep(2000);
            try
            {
                IWebElement datePickSecond = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div[1]/div/div/div[2]/div[3]/div/div[5]/div/div[2]/div[2]/table/tbody/tr[5]/td[2]/span"));
                datePickSecond.Click();
                System.Threading.Thread.Sleep(2000);
                Assert.AreNotEqual(null, browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div[1]/div/div/div[2]/div[2]/ul/li[2]/div[1]/div[1]/div[1]/div[1]")));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

            IWebElement searchFlight = browser.FindElement(By.XPath("//*[@id=\"sidebar\"]/div/div/div/div/div[2]/div[4]/a"));

            searchFlight.Click();
            System.Threading.Thread.Sleep(2000);
        }
        public void WhenSecondDateEarlierFirst()
        {
            bool       passTest   = false;
            bool       isSelected = false;
            IWebDriver Browser;

            Browser = new OpenQA.Selenium.Chrome.ChromeDriver();
            Browser.Manage().Window.Maximize();
            Browser.Navigate().GoToUrl("http://avia.321.by/");

            IWebElement InputFrom = Browser.FindElement(By.Id("from_name"));

            InputFrom.Clear();
            InputFrom.SendKeys("Лондон");
            System.Threading.Thread.Sleep(1100);
            //   InputFrom.SendKeys(OpenQA.Selenium.Keys.Enter);

            IWebElement InputTo = Browser.FindElement(By.Id("to_name"));

            InputTo.SendKeys("Минск");
            System.Threading.Thread.Sleep(1000);
            InputTo.SendKeys(OpenQA.Selenium.Keys.Enter);

            IWebElement DepatrureDate_first = Browser.FindElement(By.Id("departure_date"));

            DepatrureDate_first.Click();
            IWebElement Calendar_datefirst = Browser.FindElement(By.ClassName("date_1548882000000"));

            System.Threading.Thread.Sleep(1000);
            Calendar_datefirst.Click();

            IWebElement DepatrureDate_second = Browser.FindElement(By.Id("departure_date_1"));

            DepatrureDate_second.Click();

            IWebElement Calendar_datesecond = Browser.FindElement(By.ClassName("date_1548795600000"));

            System.Threading.Thread.Sleep(1000);
            Calendar_datesecond.Click();
            isSelected = Calendar_datesecond.Selected;

            if (!isSelected)
            {
                passTest = true;
            }

            Assert.IsTrue(passTest, "Second date is earlear then first. Input Error.");
        }
Ejemplo n.º 15
0
        //Initialise browser
        public static IWebDriver BrowserInit(string browser)
        {
            IWebDriver driver;

            switch (browser)
            {
            case "chrome":
                driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;

            default:
                driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;
            }
            //Delete all coockies
            driver.Manage().Cookies.DeleteAllCookies();
            CurrentDriver = driver;
            return(driver);
        }
Ejemplo n.º 16
0
        private IWebDriver getCurrentDriver()
        {
            OpenQA.Selenium.Remote.RemoteWebDriver driver = null;

            switch (_browserType)
            {
            case API.Enumerations.BrowserType.InternetExplorer:
                driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                break;

            case API.Enumerations.BrowserType.Firefox:
                driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                break;

            case API.Enumerations.BrowserType.Chrome:
                driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;
            }

            driver.Manage().Cookies.DeleteAllCookies();

            return(driver);
        }
Ejemplo n.º 17
0
        public void Check(string login, string password, IWebDriver browser)
        {
            var store = new Store();
            var user  = new User(login, password);

            var fs = new FileStream(store.LogFileName("Sears"), FileMode.Append, FileAccess.Write);
            var sw = new StreamWriter(fs);

            sw.WriteLine(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") + "|" + login + "|false");
            sw.Close();
            fs.Close();

            try
            {
                browser = new OpenQA.Selenium.Chrome.ChromeDriver();
                browser.Manage().Window.Maximize();
                browser.Navigate().GoToUrl("http://www.sears.com/");
                browser.Navigate()
                .GoToUrl(
                    "https://www.sears.com/universalprofile/userLogonForm?upid=3&formName=LOGIN&URL=http%3A%2F%2Fwww.sears.com%2F");
                Thread.Sleep(1000);
                browser.FindElement(By.XPath("//*[@id=\"email\"]")).Click();
                browser.FindElement(By.XPath("//*[@id=\"email\"]")).Clear();
                browser.FindElement(By.XPath("//*[@id=\"email\"]")).SendKeys(user.Login);
                browser.FindElement(By.XPath("//*[@id=\"password\"]")).Click();
                browser.FindElement(By.XPath("//*[@id=\"password\"]")).Clear();
                browser.FindElement(By.XPath("//*[@id=\"password\"]")).SendKeys(user.Password);
                browser.FindElement(By.CssSelector("button.shcBtn.shcBtnCTA.signIn")).Click();
                Thread.Sleep(1000);
                ((ITakesScreenshot)browser).GetScreenshot().SaveAsFile(store.ScreenShotFileName("Sears", user.Login),
                                                                       System.Drawing.Imaging.ImageFormat.Jpeg);
                browser.Manage().Cookies.DeleteAllCookies();
                browser.Quit();
            }
            catch (InvalidOperationException)
            {
                Store.ResultMessage("many");
                browser.Quit();
                Environment.Exit(0);
            }
            catch (NoSuchElementException e)
            {
                var result = MessageBox.Show("Something wrong: " + "\r\n" + e.Message,
                                             "Error",
                                             MessageBoxButton.OKCancel,
                                             MessageBoxImage.Error,
                                             MessageBoxResult.OK,
                                             MessageBoxOptions.ServiceNotification);

                switch (result)
                {
                case MessageBoxResult.OK:
                    sw.Close();
                    fs.Close();
                    Check(login, password, browser);
                    break;

                case MessageBoxResult.Cancel:
                    sw.WriteLine(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") + "|" + login +
                                 "|" + password + "|exception|" + e.Message);
                    break;
                }
            }
            catch (WebDriverException)
            {
                Store.ResultMessage("many");
                browser.Quit();
                Environment.Exit(0);
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
        public async void FBLogin(String user, String pass)
        {
            Program.mainForm.btnLogin.Enabled = false;

            if (user == "" || pass == "")
            {
                MessageBox.Show("Điền thông tin đăng nhập!");
                Program.mainForm.btnLogin.Enabled = true;
                return;
            }

            //Program.loadingForm = new LoadingForm();
            //Program.loadingForm.setText("KHỞI TẠO HỆ THỐNG...");
            //Program.loadingForm.Show();
            //Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(() => Program.loadingForm.ShowDialog()));

            //t = new System.Threading.Thread(() => Program.loadingForm.ShowDialog());
            //t.Start(); // LoadingForm.Show()
            // Bật trình duyệt khi Login
            if (driver == null)
            {
                setReady(false, "Đang khởi tạo hệ thống");
                //var profile = new OpenQA.Selenium.Firefox.FirefoxProfile();
                //profile.SetPreference("general.useragent.override", "NokiaC5-00/061.005 (SymbianOS/9.3; U; Series60/3.2 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 Safari/525 3gpp-gba");
                //profile.SetPreference("webdriver.load.strategy", "unstable");
                //profile.SetPreference("permissions.default.stylesheet", 2);
                //profile.SetPreference("permissions.default.image", 2);
                //profile.AddExtension("App/Firefox/firebug.xpi");
                //profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
                IEnumerable<int> pidsBefore = Process.GetProcessesByName("chrome").Select(p => p.Id);
                try
                {
                    //this.driver = await Task.Factory.StartNew(() => new OpenQA.Selenium.Firefox.FirefoxDriver(profile));
                    /*
                    OpenQA.Selenium.Firefox.FirefoxBinary firefox = new OpenQA.Selenium.Firefox.FirefoxBinary("App/Firefox/firefox.exe");
                    this.driver = new OpenQA.Selenium.Firefox.FirefoxDriver(firefox, profile);*/
                    var chromeDriverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(Application.ExecutablePath) + @"\App");
                    chromeDriverService.HideCommandPromptWindow = true;
                    OpenQA.Selenium.Chrome.ChromeOptions chromeDriverOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
                    chromeDriverOptions.AddArgument("--user-agent=NokiaC5-00/061.005 (SymbianOS/9.3; U; Series60/3.2 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) Version/3.0 Safari/525 3gpp-gba"); //Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0
                    chromeDriverOptions.AddArgument("ignore-certificate-errors");
                    chromeDriverOptions.AddArgument("no-sandbox");
                    chromeDriverOptions.AddExtension(Path.GetDirectoryName(Application.ExecutablePath) + @"\App\block.crx");
                    driver = await Task.Factory.StartNew(() => new OpenQA.Selenium.Chrome.ChromeDriver(chromeDriverService, chromeDriverOptions));
                    //Thread.Sleep(1000);
                }
                catch
                {
                    //Program.loadingForm.RequestStop();
                    MessageBox.Show("Thiếu File!?");
                    /*
                    if (MessageBox.Show("Để chạy chương trình, bạn cần cài đặt trình duyệt Mozilla Firefox tích hợp. Cài đặt ngay?", "Cài đặt trình duyệt", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                    {
                        MessageBox.Show("Chương trình có thể bị treo trong vài giây tới. Nhấn OK để bắt đầu cài đặt!");
                        // install firefox 34
                        ProcessStartInfo startInfo = new ProcessStartInfo();
                        startInfo.CreateNoWindow = false;
                        startInfo.UseShellExecute = false;
                        startInfo.FileName = "firefox34.exe";
                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        startInfo.Arguments = "-ms";
                        try
                        {
                            using (Process exeProcess = Process.Start(startInfo))
                            {
                                exeProcess.WaitForExit();
                            }
                        }
                        catch { }

                        string[] folders = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Mozilla\\Firefox\\Profiles\\", "*.default");
                        string prefs_js = folders[0] + "\\prefs.js";

                        StreamWriter sw;
                        sw = File.AppendText(prefs_js);
                        sw.WriteLine("user_pref('app.update.auto', false);");
                        sw.WriteLine("user_pref('app.update.enabled', false);");
                        sw.Close();

                        MessageBox.Show("Hoàn thành cài đặt! Hãy khởi động lại chương trình!");
                    }*/

                    Exceptions_Handler();
                }
                IEnumerable<int> pidsAfter = Process.GetProcessesByName("chrome").Select(p => p.Id);

                newFirefoxPids = pidsAfter.Except(pidsBefore);

                try
                {
                    foreach (int pid in newFirefoxPids)
                    {
                        int hWnd = Process.GetProcessById(pid).MainWindowHandle.ToInt32();
                        ShowWindow(hWnd, SW_HIDE);
                    }
                }
                catch
                {
                    // newFirefoxPids.Count == 0
                    //Program.loadingForm.RequestStop();
                    MessageBox.Show("Không tìm thấy cửa sổ Trình duyệt!");
                    Exceptions_Handler();
                }

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
                driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));
                setReady(true);
            }

            //Program.loadingForm.setText("ĐĂNG NHẬP TÀI KHOẢN FACEBOOK...");
            setReady(false, "Đang đăng nhập");
            await Task.Factory.StartNew(() => Navigate(links["fb_url"]));

            if (await Task.Factory.StartNew(() => driver.FindElementsByName("email").Count) == 0)
            {
                //Program.loadingForm.RequestStop();
                //t.Abort();
                //t.Join();
                MessageBox.Show("Có lỗi với đường truyền mạng hoặc tài khoản facebook của bạn!\nHãy kiểm tra lại");
                Program.mainForm.btnLogin.Enabled = true;
                Program.mainForm.txtUser.Enabled = true;
                Program.mainForm.txtPass.Enabled = true;
                foreach (Control item in Program.mainForm.dgGroups.Controls.OfType<Control>())
                {
                    if (item.Name == "group_loading_gif")
                        Program.mainForm.dgGroups.Controls.Remove(item);
                }
                setReady(true);
                return;
            }
            
            await Task.Factory.StartNew(() => InputValueAdd("email", user));
            await Task.Factory.StartNew(() => InputValueAdd("pass", pass));
            await Task.Factory.StartNew(() => Click("login"));
            /*
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
            await Task.Factory.StartNew(() => wait.Until<IWebElement>((d) =>
            {
                return d.FindElement(By.Name("xc_message"));
            }));*/
            //await Task.Factory.StartNew(() => ((IJavaScriptExecutor)driver).ExecuteScript("alert(123)"));
            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(300));
            string after_login_url = await Task.Factory.StartNew(() => driver.Url);
            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));

            check_after_login:
            if (after_login_url.Contains("home.php") || after_login_url.Contains("phoneacquire"))
            {
                Program.mainForm.btnLogin.Text = "Đăng nhập thành công!";
                Program.mainForm.AcceptButton = null;
                Program.mainForm.btnPost.Enabled = true;
                Program.mainForm.btnInvite.Enabled = true;
                Program.mainForm.btnGroupSearch.Enabled = true;
                Program.mainForm.btnGroupJoin.Enabled = true;
                Program.mainForm.btnPMImportFriends.Enabled = true;
                Program.mainForm.btnPM.Enabled = true;
                Program.mainForm.btnPMSendFrRequests.Enabled = true;
                Program.mainForm.btnInteractionsFollow.Enabled = true;
                Program.mainForm.btnInteractionsPoke.Enabled = true;
                Program.mainForm.btnInteractionsLike.Enabled = true;
                Program.mainForm.btnPMImportProfile.Enabled = true;
                Program.mainForm.btnPMImportGroup.Enabled = true;
                Program.mainForm.btnCommentImportComment.Enabled = true;
                Program.mainForm.btnPostImportGroups.Enabled = true;
                Program.mainForm.btnGroupImportFriends.Enabled = true;
                Program.mainForm.btnCommentScan.Enabled = true;
                Program.mainForm.btnFanpageComment.Enabled = true;
                Program.mainForm.btnFanpageGroupPost.Enabled = true;
                Program.mainForm.btnEventInviteFriends.Enabled = true;
                Program.mainForm.btnFanpageSeeder.Enabled = true;
                Program.mainForm.btnFanpageInviteFriends.Enabled = true;
                Program.mainForm.btnFanpageLike.Enabled = true;
                Program.mainForm.btnGraphSearch.Enabled = true;
                
                var photos = await Task.Factory.StartNew(() => driver.FindElementsByXPath("//a[contains(@href, '?v=photos')]"));
                if (photos.Count > 0)
                {
                    String href = photos[0].GetAttribute("href");
                    Match match = Regex.Match(href, @".com\/([A-Za-z0-9\-\.]+)\?v\=photos", RegexOptions.None);
                    if (match.Success)
                    {
                        user_id = match.Groups[1].Value;
                    }
                }

                var nodes = await Task.Factory.StartNew(() => driver.FindElementsByXPath("//img[contains(@src, 'fbcdn-profile-a.akamaihd.net')]"));
                if (nodes.Count > 0)
                {
                    Program.mainForm.lblUsername.Text = nodes[0].GetAttribute("alt");
                }

                try
                {
                    user_id_img = user_id;
                    await Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            user_id_img = driver.FindElementByName("target").GetAttribute("value");
                        }
                        catch { }
                    });

                    Program.mainForm.pbAvatar.WaitOnLoad = false;
                    Program.mainForm.pbAvatar.LoadAsync(links["facebook_graph"] + "/" + user_id_img + "/picture");
                    Program.mainForm.lblViewProfile.Text = "https://facebook.com/" + user_id_img;
                }
                catch { }
                
                //Program.mainForm.Focus();
                //Program.loadingForm.setText("ĐĂNG NHẬP THÀNH CÔNG! ĐANG TẢI DANH SÁCH NHÓM...");
                Program.mainForm.lblStatus.Text = "Tải danh sách nhóm...";
                Program.mainForm.dgGroups.Rows.Clear();
                if (Program.mainForm.cbGroupReload.Checked)
                {
                    try
                    {
                        DataSet DS = new DataSet();
                        DS.ReadXml(RemoveSpecialCharacters(user_id_img) + "_groups.xml");

                        bool empty = true;

                        foreach (DataRow dr in DS.Tables[0].Rows)
                        {
                            Program.mainForm.dgGroups.Rows.Add(dr[0], dr[1], dr[2], dr[3]);
                            await TaskEx.Delay(1);
                            if (dr[3].ToString() == "1") empty = false;
                        }

                        if (empty)
                        {
                            foreach (DataGridViewRow row in Program.mainForm.dgGroups.Rows)
                            {
                                DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells[3];
                                chk.Value = 1;
                            }
                        }
                    }
                    catch { }
                }

                if (Program.mainForm.dgGroups.RowCount == 0) await getGroups();
                else
                {
                    //Program.loadingForm.RequestStop();
                    //t.Abort();
                    //t.Join();
                    Program.mainForm.lblProgress.Text = "0/" + Program.mainForm.dgGroups.Rows.Count;
                    setReady(true, "Số lượng nhóm: " + Program.mainForm.dgGroups.Rows.Count);
                }

                Program.mainForm.btnLogin.Text = "Đăng xuất";
                Program.mainForm.btnLogin.Enabled = true;

                foreach (Control item in Program.mainForm.dgGroups.Controls.OfType<Control>())
                {
                    if (item.Name == "group_loading_gif")
                        Program.mainForm.dgGroups.Controls.Remove(item);
                }
            }
            else
            {
                if (getUrl().Contains("home.php"))
                {
                    goto check_after_login; // check again, just in case 100ms is not enough
                }

                Program.mainForm.txtUser.Enabled = true;
                Program.mainForm.txtPass.Enabled = true;
                foreach (Control item in Program.mainForm.dgGroups.Controls.OfType<Control>())
                {
                    if (item.Name == "group_loading_gif")
                        Program.mainForm.dgGroups.Controls.Remove(item);
                }
                //Program.loadingForm.RequestStop();
                //t.Abort();
                //t.Join();
                if (getUrl().Contains("checkpoint"))
                    MessageBox.Show("Hãy vô hiệu hóa bảo mật tài khoản trước khi sử dụng AUTO!");
                
                MessageBox.Show("Kiểm tra lại thông tin đăng nhập!\nNếu bạn chắc chắn thông tin đăng nhập là đúng,\nhãy đăng nhập lại tài khoản trên trình duyệt trước khi tiếp tục!");
                Program.mainForm.btnLogin.Enabled = true;
                setReady(true);
                return;
            }
            // await Task.Factory.StartNew(() => new WebDriverWait(driver, TimeSpan.FromSeconds(10))); // Chờ tải xong trang
        }
        private async Task ChromeAgent()
        {
            if (driver2 != null)
            {
                return;
            }
            ready2 = false;
            Program.mainForm.lblStatus.Text = "Khởi tạo kết nối nâng cao";

            IEnumerable<int> pidsBefore = Process.GetProcessesByName("chrome").Select(p => p.Id);

            var chromeDriverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(Application.ExecutablePath) + @"\App");
            chromeDriverService.HideCommandPromptWindow = true;
            OpenQA.Selenium.Chrome.ChromeOptions chromeDriverOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
            driver2 = await Task.Factory.StartNew(() => new OpenQA.Selenium.Chrome.ChromeDriver(chromeDriverService, chromeDriverOptions));


            IEnumerable<int> pidsAfter = Process.GetProcessesByName("chrome").Select(p => p.Id);
            var newChromePids = pidsAfter.Except(pidsBefore);

            try
            {
                foreach (int pid in newChromePids)
                {
                    int hWnd = Process.GetProcessById(pid).MainWindowHandle.ToInt32();
                    ShowWindow(hWnd, SW_HIDE);
                }
            }
            catch
            {
                MessageBox.Show("Có lỗi xảy ra! Hãy khởi động lại chương trình");
                Exceptions_Handler();
            }

            Program.mainForm.lblStatus.Text = "Thiết lập kết nối nâng cao";

            driver2.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            await Task.Factory.StartNew(() => driver2.Url = "https://www.facebook.com/");


            WebDriverWait wait = new WebDriverWait(driver2, TimeSpan.FromSeconds(60));

            await Task.Factory.StartNew(() =>
            {
                try
                {
                    driver2.Url = "https://www.facebook.com/";
                }
                catch
                {
                    ((IJavaScriptExecutor)driver2).ExecuteScript("return window.stop()");
                }
            });

            await Task.Factory.StartNew(() =>
            {
                wait.Until<Boolean>((d) =>
                {
                    return ((IJavaScriptExecutor)driver2).ExecuteScript("return document.readyState").Equals("complete");
                });
            });

            try
            {
                driver2.ExecuteScript(@"document.getElementsByName('email')[0].value = '" + System.Web.HttpUtility.JavaScriptStringEncode(Program.mainForm.txtUser.Text) + "';");
            }
            catch
            {
                MessageBox.Show("Đường truyền mạng quá chậm, vui lòng thử lại sau!");
                Exceptions_Handler();
            }

            await Task.Factory.StartNew(() =>
            {
                driver2.ExecuteScript(@"document.getElementsByName('pass')[0].value = '" + System.Web.HttpUtility.JavaScriptStringEncode(Program.mainForm.txtPass.Text) + "';");
                driver2.ExecuteScript(@"document.getElementById('loginbutton').click();");
            });

            await Task.Factory.StartNew(() =>
            {
                wait.Until<Boolean>((d) =>
                {
                    return ((IJavaScriptExecutor)driver2).ExecuteScript("return document.readyState").Equals("complete");
                });
            });

            await TaskEx.Delay(1000);
            ready2 = true;
        }