public bool Follow() { IWebElement followSucces = null; var followButton = InstaDriver.FindElementByXPath("//*[contains(@type,'button') and text() = 'Follow']"); followButton.Click(); try { followSucces = DriverExtensions.FindElement(InstaDriver, By.XPath("//*[contains(@type,'button') and text() = 'Message']"), 20); LogHelper.Log($"Succesfully followed {_userProfileURL}"); } catch (Exception ex) { LogHelper.Log($"Failed to follow {_userProfileURL} ---- {ex.GetType()}"); } if (followButton != null) { return(true); } else { return(false); } }
public ICollection <ScrapedUser> ScrapeUsersByStrategy(int usersToScrape, IScrapingMethod scrapingStrategy) { var listOfUrls = GetFollowersURLsFromUserProfile().ToList(); var maxThreads = GetNumberOfCores() - 1; var batchSize = Convert.ToInt16(Convert.ToDouble(listOfUrls.Count) / Convert.ToDouble(maxThreads)); var listWithListsOfUrls = new List <List <string> >(); foreach (var batch in listOfUrls.Batch(batchSize)) { listWithListsOfUrls.Add(batch.ToList()); } var listOfTasks = new List <Task <ICollection <ScrapedUser> > >(); foreach (var list in listWithListsOfUrls) { var task = Task <ICollection <ScrapedUser> > .Factory.StartNew(() => GetResultsFromScraping(scrapingStrategy, list)); listOfTasks.Add(task); } Task.WaitAll(listOfTasks.ToArray()); List <ScrapedUser> results = new List <ScrapedUser>(); foreach (var task in listOfTasks) { results.AddRange(task.Result); } DriverExtensions.KillProcesses(); return(results); }
public void ThenShouldBeLoggedIn() { home = new HomePage(driver); home.HomeLink.Click(); home.MyAccount.Click(); GetScreesnhot(); Assert.IsTrue(DriverExtensions.FindElement(driver, By.XPath("//h1[text()='My account']"), 10).Displayed); GetScreesnhot(); }
public void Logout() { _driver = DriverSetUp.Driver; _driver.FindElement(By.Id("btnLogout")).Click(); //LogoutButton.Click(); if (DriverExtensions.isAlertPresent(_driver)) { _driver.SwitchTo().Alert().Accept(); } }
public void PassLoginPopUps() { try { IWebElement saveLoginInfo = DriverExtensions.FindElement(InstaDriver, By.XPath("//*[contains(@class,'sqdOP yWX7d y3zKF ')]"), 20); saveLoginInfo.Click(); IWebElement turnOnNotifications = DriverExtensions.FindElement(InstaDriver, By.XPath("//*[contains(@class,'aOOlW HoLwm ')]"), 20); turnOnNotifications.Click(); } catch (Exception ex) { } }
//public DashboardPage() //{ // _driver = DriverSetUp.Driver; //} //[FindsBy(How = How.XPath, Using = ".//*[@id='wrapper']/nav/div/ul/li[10]/a/img")] //private IWebElement GoTemplateButton { get; set; } public void GoTemplatePage() { _driver = DriverSetUp.Driver; if (!DriverExtensions.isOnSpecialPage(_driver, "Templates.htm")) { _driver.FindElement(By.XPath(".//*[@id='wrapper']/nav/div/ul/li[10]/a/img"), 120).Click(); //new WebDriverWait(_driver, TimeSpan.FromSeconds(120)). // Until(ExpectedConditions.ElementExists(By.XPath(".//*[@id='wrapper']/nav/div/ul/li[10]/a/img"))); //GoTemplateButton.Click(); } }
public virtual void SelectOptionByText(string optionText) { if (!this.IsDropdownExpanded()) { this.ToggleDropdown(); } this.GetAvailableOptionsElements() .FirstOrDefault(o => DriverExtensions.GetHiddentText(o).Contains(optionText)) .Click(); }
public void TestToBePassed() { FinancePage fp = new FinancePage(); fp.Load(); IWebElement container = Driver.Instance.FindElement(By.CssSelector("div.additional_news li")); By subElement = By.ClassName("_title"); var test1 = container.FindElement(new ByChained(subElement)).Text; System.Console.WriteLine(test1); var test = DriverExtensions.GetElement(container, subElement).Text; System.Console.WriteLine(test); Assert.IsTrue(true); }
//private string _HomeUrl; //public LoginPage() //{ // _driver = DriverSetUp.Driver; // _HomeUrl = InitData.suiteStore.Get<string>("BaseUrl"); //} //public static readonly string HomeUrl = Environment.GetEnvironmentVariable("BaseUrl"); ////public static readonly string HomeUrl = D //[FindsBy(How = How.Id, Using = "user")] //private IWebElement UserName { get; set; } //[FindsBy(How = How.Id, Using = "pwd")] //private IWebElement Password { get; set; } //[FindsBy(How = How.Id, Using = "submit")] //private IWebElement Submit { get; set; } public void LoginFMWeb(string usename, string password) { _driver = DriverSetUp.Driver; _driver.FindElement(By.Id("user")).SendKeys(usename); _driver.FindElement(By.Id("pwd")).SendKeys(password); _driver.FindElement(By.Id("submit")).Click(); //DriverExtensions.EnterText(UserName, usename); //DriverExtensions.EnterText(Password, password); //Submit.Click(); if (DriverExtensions.isAlertPresent(_driver)) { _driver.SwitchTo().Alert().Accept(); } }
public Home PerformLogin(string emailOrPhone) { InstagramAccount instaAccount = null; try { instaAccount = SQLiteDatabaseAccess.GetInstagramAccount(emailOrPhone); LoggedAccount = emailOrPhone; } catch (Exception ex) { } if (instaAccount != null) { try { IWebElement cookiesAccept = DriverExtensions.FindElement(InstaDriver, By.XPath("//*[contains(@class,'aOOlW bIiDR ')]"), 20); cookiesAccept.Click(); IWebElement loginEmail = InstaDriver.FindElementByXPath("//*[contains(@aria-label,'Phone number, username, or email')]"); loginEmail.SendKeys(emailOrPhone); IWebElement loginPassword = InstaDriver.FindElementByXPath("//*[contains(@aria-label,'Password')]"); loginPassword.SendKeys(instaAccount.Password); IWebElement loginButton = InstaDriver.FindElementByXPath("//*[contains(@type,'submit')]"); loginButton.Click(); if (CheckIsLoggedIn()) { PassLoginPopUps(); LogHelper.Log("Succesfully logged in"); return(new Home(InstaDriver)); } } catch (Exception ex) { LogHelper.Log($"Some error occured trying to login..., {ex.GetType()}"); } } return(null); }
public UserProfile GoToUserProfile(string stringToSearch = "", bool isGoByURL = false) { UserProfile userProfile = null; if (isGoByURL) { try { InstaDriver.Navigate().GoToUrl(stringToSearch); userProfile = new UserProfile(InstaDriver, InstaDriver.Url); LogHelper.Log($"Succesfully navigated to user profile {stringToSearch}"); } catch (Exception ex) { LogHelper.Log($"Failed to navigate to user profile {stringToSearch}"); } } else { try { if (stringToSearch != string.Empty) { IWebElement searchBar = InstaDriver.FindElementByXPath("//*[contains(@placeholder,'Search')]"); searchBar.SendKeys(stringToSearch); IWebElement firstResultFromList = DriverExtensions.FindElements(InstaDriver, By.XPath("//*[contains(@class,'yCE8d ')]"), 20)[0]; firstResultFromList.Click(); userProfile = new UserProfile(InstaDriver, InstaDriver.Url); LogHelper.Log($"Succesfully navigated to user profile {stringToSearch}"); } } catch (Exception ex) { LogHelper.Log($"Failed to navigate to user profile {stringToSearch}"); } } return(userProfile); }
public ICollection <string> GetFollowersURLsFromUserProfile() { IWebElement followersElement = InstaDriver.FindElementByXPath("//a[contains(@href,'followers')]"); followersElement.Click(); IWebElement mainList = InstaDriver.FindElementByXPath("//*[contains(@class,'isgrP')]"); ScrollDown(30); var listOfURLs = new List <string>(); foreach (var userElement in InstaDriver.FindElementsByXPath("//a[contains(@class,'_2dbep qNELH kIKUG')]")) { listOfURLs.Add(userElement.GetAttribute("href")); } LogHelper.Log($"Started to scrape users of {_userProfileURL}"); InstaDriver.Quit(); DriverExtensions.KillProcesses(); return(listOfURLs); }
public virtual void ToggleDropdown() => DriverExtensions.WaitForElement(ExpandDropdownButtonLocator).Click();
public virtual bool IsDropdownExpanded() => DriverExtensions.WaitForElement(ExpandDropdownButtonLocator).GetAttribute("aria-expanded").Equals("true");
public void Click() { DriverExtensions.WaitForElement(this.ButtonLocator).Click(); }
public List <T> GetItems() => DriverExtensions.GetElements(this.ListItemLct) .Select(itemContainer => (T)Activator.CreateInstance(typeof(T), itemContainer)) .ToList();
public List <IWebElement> GetItems() => DriverExtensions.WaitForElement(this.ListItemLocator).FindElements(this.ListItemLocator).ToList();
public virtual bool IsDropdownDisplayed() => DriverExtensions.WaitForElement(DropDownContainerLocator).Displayed;
public virtual List <string> GetAvailableOptions() => this.GetAvailableOptionsElements().Select(o => DriverExtensions.GetHiddentText(o)).ToList();
public virtual void Click() => DriverExtensions.WaitForElement(TabLocator).Click();
public virtual bool IsDisplayed() => DriverExtensions.WaitForElement(TabLocator).Displayed;