private void AddPagesIntoList(FbPageInfo obj)
 {
     App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
     {
         PageList.Add(obj);
     });
     //Task.Factory.StartNew(() => FillPageList());
 }
        public void LoginWithSelenium(string userName, string password)
        {
            try
            {
                passWord = password;
                FbPageInfo fbPageInfo = new FbPageInfo();

                Login(userName, passWord);

                //  chromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages");
                // ChromeWebDriver.Navigate().GoToUrl(url);
                // Thread.Sleep(2000);
                //ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558");
                try
                {
                    var emailElement1 = chromeWebDriver.FindElements(By.XPath("//a[@class='_39g5']"));
                    foreach (var item in emailElement1)
                    {
                        string lin1k = item.GetAttribute("href");
                        if (item.GetAttribute("href").Contains("/live_video/launch_composer/?page_id="))
                        {
                            string pageId = lin1k.Replace("https://www.facebook.com/live_video/launch_composer/?page_id=", "");
                        }
                        if (item.GetAttribute("href").Contains("?modal=composer&ref=www_pages_browser_your_pages_section"))
                        {
                            string pageName = lin1k.Replace("https://www.facebook.com/", "").Replace("/?modal=composer&ref=www_pages_browser_your_pages_section", "");
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    _cookieJar = chromeWebDriver.Manage().Cookies;

                    // chromeWebDriver.Quit();
                }
                //Thread.Sleep(5000);

                LoginSuccessEvent();

                //  Thread.Sleep(2000);
                //}
            }
            catch (Exception)
            {
                //;
            }
        }
        private void GetaalPage(string perentUserId)
        {
            var            listFbPageInfo    = new List <FbPageInfo>();
            Queue <string> queueFbCmntImgUrl = new Queue <string>();

            //var chromeWebDriver = GetDriver();
            //SetCookies(chromeWebDriver);
            chromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages");
            try {
                ReadOnlyCollection <IWebElement> pageNodepageUrl = chromeWebDriver.FindElements((By.XPath("//*[@class='clearfix _1vh8']/a")));
                if (pageNodepageUrl.Count > 0)
                {
                    foreach (var pageNodeItem in pageNodepageUrl)
                    {
                        var TemppageNodeItem = pageNodeItem.GetAttribute("href");

                        //fbPageInfo.FbPageUrl = TemppageNodeItem;
                        //    LstPageUrl.Add(TemppageNodeItem);

                        queueFbCmntImgUrl.Enqueue(TemppageNodeItem);
                    }
                    ArrayList  arrlist1   = new ArrayList();
                    ArrayList  arrlist2   = new ArrayList();
                    FbPageInfo fbPageInfo = new FbPageInfo();


                    var emailElement1 = chromeWebDriver.FindElements(By.XPath("//a[@class='_39g5']"));
                    foreach (var item in emailElement1)
                    {
                        string lin1k = item.GetAttribute("href");
                        if (item.GetAttribute("href").Contains("/live_video/launch_composer/?page_id="))
                        {
                            var pageId = lin1k.Replace("https://www.facebook.com/live_video/launch_composer/?page_id=", "");
                            arrlist1.Add(pageId);
                            //fbPageInfo.FbPageId = pageId;
                        }
                        if (item.GetAttribute("href").Contains("?modal=composer&ref=www_pages_browser_your_pages_section"))
                        {
                            string pageName = lin1k.Replace("https://www.facebook.com/", "").Replace("/?modal=composer&ref=www_pages_browser_your_pages_section", "");
                            arrlist2.Add(pageName);
                        }
                    }
                    var dbHelper = new DbHelper();

                    for (int i = 0; i < queueFbCmntImgUrl.Count; i++)
                    {
                        fbPageInfo.FbPageId   = arrlist1[i].ToString();
                        fbPageInfo.FbPageName = arrlist2[i].ToString();
                        var fbPageUrl = queueFbCmntImgUrl.Dequeue();
                        fbPageInfo.FbPageUrl = fbPageUrl.Split('?')[0] + "inbox/?";

                        listFbPageInfo.Add(fbPageInfo);
                        //     _dbHelper.GetLoginUsers();
                        dbHelper.AddFacebookPage(fbPageInfo.FbPageId, fbPageInfo.FbPageName, fbPageInfo.FbPageUrl, perentUserId);
                    }
                }
            } catch (Exception) {
            } finally {
                chromeWebDriver.Quit();
            }
        }
        public void LoginWithSelenium(string userName, string password)
        {
            try
            {
                FbPageInfo fbPageInfo = new FbPageInfo();

                string       appStartupPath = System.IO.Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
                const string url            = "https://www.facebook.com/pages/?category=your_pages";
                _options.AddArgument("--disable-notifications");
                _options.AddArgument("--disable-extensions");
                _options.AddArgument("--test-type");
                _options.AddArgument("--log-level=3");
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(appStartupPath);
                chromeDriverService.HideCommandPromptWindow = true;
                chromeWebDriver = new ChromeDriver(chromeDriverService, _options);
                chromeWebDriver.Manage().Window.Maximize();
                chromeWebDriver.Navigate().GoToUrl(url);
                try
                {
                    ((IJavaScriptExecutor)chromeWebDriver).ExecuteScript("window.onbeforeunload = function(e){};");
                }
                catch (Exception)
                {
                }

                ReadOnlyCollection <IWebElement> emailElement = chromeWebDriver.FindElements(By.Id("email"));
                if (emailElement.Count > 0)
                {
                    // emailElement[0].SendKeys("*****@*****.**");

                    emailElement[0].SendKeys(userName);

                    //CurrentLogedInFacebookUserinfo.Username = facebookUserinfo.Username
                }
                ReadOnlyCollection <IWebElement> passwordElement = chromeWebDriver.FindElements(By.Id("pass"));
                if (passwordElement.Count > 0)
                {
                    passwordElement[0].SendKeys(password);
                    // passwordElement[0].SendKeys(FileOperation.Password);
                }


                ReadOnlyCollection <IWebElement> signInElement = chromeWebDriver.FindElements(By.Id("loginbutton"));
                if (signInElement.Count > 0)
                {
                    signInElement[0].Click();
                    Thread.Sleep(3000);
                    //  chromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages");
                    // ChromeWebDriver.Navigate().GoToUrl(url);
                    // Thread.Sleep(2000);
                    //ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558");
                    try
                    {
                        var emailElement1 = chromeWebDriver.FindElements(By.XPath("//a[@class='_39g5']"));
                        foreach (var item in emailElement1)
                        {
                            string lin1k = item.GetAttribute("href");
                            if (item.GetAttribute("href").Contains("/live_video/launch_composer/?page_id="))
                            {
                                string pageId = lin1k.Replace("https://www.facebook.com/live_video/launch_composer/?page_id=", "");
                            }
                            if (item.GetAttribute("href").Contains("?modal=composer&ref=www_pages_browser_your_pages_section"))
                            {
                                string pageName = lin1k.Replace("https://www.facebook.com/", "").Replace("/?modal=composer&ref=www_pages_browser_your_pages_section", "");
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        _cookieJar = chromeWebDriver.Manage().Cookies;

                        // chromeWebDriver.Quit();
                    }
                    //Thread.Sleep(5000);

                    LoginSuccessEvent();
                    // isLoggedIn = true;
                    //  Thread.Sleep(2000);
                }
            }
            catch (Exception)
            {
                //;
            }
        }