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); } }
private void ScrollDown(int seconds) { Stopwatch s = new Stopwatch(); s.Start(); while (s.Elapsed < TimeSpan.FromSeconds(seconds)) { var listOfaccs = InstaDriver.FindElementsByXPath("//a[contains(@class,'_2dbep qNELH kIKUG')]"); var lastElement = listOfaccs[listOfaccs.Count - 2]; InstaDriver.ExecuteScript("arguments[0].scrollIntoView(true);", lastElement); } s.Stop(); }
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 bool CheckIsLoggedIn() { IWebElement searchBar = null; int maxRetry = 10; while (searchBar == null && maxRetry > 0) { searchBar = InstaDriver.FindElementByXPath("//*[contains(@class,'LWmhU _0aCwM')]"); maxRetry--; } if (searchBar != null) { return(true); } else { return(false); } }
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); }