Пример #1
0
        private void AdminCreatePost(FbPost fbPost)
        {
            if (ConfigurationManager.AppSettings["Admin.Power"].ToUpper() != "ON")
            {
                return;
            }
            if (ConfigurationManager.AppSettings["Admin.ModeWebOrSql"].ToUpper() != "WEB")
            {
                return;
            }

            if (ConfigurationManager.AppSettings["Admin.Power"].ToUpper() != "ON")
            {
                return;
            }

            var humanizer = new Humanizer.Humanizer(_driver);
            var wait      = new WebDriverWait(_driver, TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["Admin.TimeoutSeconds"])));

            _logger.Info($"Записване на пост админ панела: {fbPost.ToString()}");

            _driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["Admin.CreatePostUrl"]);
            wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("iframe")));
            _driver.SwitchTo().Frame(0);
            _driver.FindElement(By.LinkText("Добави известие")).Click();

            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("Import_url")));

            // fill in meta data
            _driver.FindElement(By.Id("Import_url")).SendKeys(fbPost.FbPostUrl);
            _driver.FindElement(By.Id("Import_id_post")).SendKeys(fbPost.FbPostId);
            _driver.FindElement(By.Id("Import_contact_info")).SendKeys(fbPost.FbPostAuthor);

            // fill in post data
            _driver.FindElement(By.CssSelector("a[title='Код']")).Click();
            wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("a[title='Код']")));
            _driver.FindElement(By.ClassName("cke_source")).SetAttribute("value", fbPost.FbFullHtml);

            _driver.FindElement(By.CssSelector("input[type='submit']")).Click();
            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("massiveOperation")));
            humanizer.WaitRandom();
        }
Пример #2
0
        static void FacebookLogin(IWebDriver driver)
        {
            _logger.Info("Влизане във Фейсбук...");
            var humanizer = new Humanizer.Humanizer(driver);
            var wait      = new WebDriverWait(driver, TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["Facebook.TimeoutSeconds"])));

            driver.Navigate().GoToUrl("https://facebook.com");

            wait.Until(ExpectedConditions.ElementIsVisible(By.Name("email")));

            var elUser = driver.FindElement(By.Name("email"));
            var elPass = driver.FindElement(By.Name("pass"));

            elUser.SendKeys(ConfigurationManager.AppSettings["Facebook.Username"]);
            elPass.SendKeys(ConfigurationManager.AppSettings["Facebook.Password"]);
            elPass.SendKeys(Keys.Return);

            humanizer.WaitRandom();
            _logger.Info("Влизането във Фейсбук е успешно");
        }
Пример #3
0
        private void SubscribeToPost(IWebElement element)
        {
            string dropdownSelector     = "a[aria-label=\"Опции за историята\"";
            string menuItemsSelector    = ".__MenuItem[role='presentation']";
            string messageCloseSelector = "button[title='Премахване']";
            var    humanizer            = new Humanizer.Humanizer(_driver);
            var    wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["Facebook.TimeoutSeconds"])));

            if (_driver.FindElements(By.CssSelector("[role = 'banner']")).Count > 0)
            {
                ((IJavaScriptExecutor)_driver).ExecuteScript("document.querySelectorAll(\"[role = 'banner']\")[0].remove()");
            }

            var dropdown = element.FindElement(By.CssSelector(dropdownSelector));

            dropdown.Click();
            // necessary to wait since because next func is very slow
            if (humanizer.Enabled)
            {
                humanizer.WaitRandom();
            }
            else
            {
                Thread.Sleep(1000);
            }

            // wait for menu items to show up
            wait.Until <bool>((d) => {
                var mItems         = d.FindElements(By.CssSelector(menuItemsSelector));
                var mItemsRelevant = mItems.Where(mi => {
                    if (!mi.Enabled)
                    {
                        return(false);
                    }
                    if (mi.Text.Contains("Включване на известия за тази публикация") ||
                        mi.Text.Contains("Изключване на известията за тази публикация"))
                    {
                        return(true);
                    }
                    return(false);
                }).ToList();

                return(mItemsRelevant.Count > 0);
            });

            var menuItems         = _driver.FindElements(By.CssSelector(menuItemsSelector));
            var subscribeMenuItem = menuItems.Where(mi => {
                if (!mi.Enabled)
                {
                    return(false);
                }
                if (mi.Text.Contains("Включване на известия за тази публикация") ||
                    mi.Text.Contains("Изключване на известията за тази публикация"))
                {
                    return(true);
                }
                return(false);
            }).First();

            if (!subscribeMenuItem.GetInnerText().Contains("Включване"))
            {
                // already subscribed, don't want to unsubscribe
                return;
            }
            _driver.Hover(subscribeMenuItem);
            humanizer.WaitRandom();
            subscribeMenuItem.Click();
            if (humanizer.Enabled)
            {
                humanizer.WaitRandom();
            }
            else
            {
                Thread.Sleep(1000);
            }
        }