public async Task Browse(Credential credential, Guid sourceId) { var driver = new ChromeDriver(new ChromeOptions { PageLoadStrategy = PageLoadStrategy.Eager }); WebDriverWait _wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10)); try { driver.Navigate().GoToUrl("https://www.linkedin.com/login"); driver.ExecuteScript("console.log('hi!')"); _wait.Until(d => d.FindElement(By.Id("username"))); driver.FindElement(By.Id("username")).SendKeys(credential.ExternalIdentifier); var passwordTextfield = driver.FindElement(By.Id("password")); passwordTextfield.SendKeys(credential.ExternalSecret); var button = driver.FindElement(By.CssSelector("button[aria-label='Sign in']")); button.Click(); await Task.Delay(1000); driver.Navigate().GoToUrl("https://www.linkedin.com/mynetwork/invite-connect/connections/"); driver.ExecuteScript(RECORD_XHR_BLOBS); _wait.Until(d => d.FindElement(By.CssSelector("[aria-label='Sorting options for connections list']"))); var dropdown = driver.FindElement(By.CssSelector("[aria-label='Sorting options for connections list']")); dropdown.Click(); driver.FindElement(By.CssSelector("[data-control-name='sort_by_recently_added']")).Click(); _wait.Until(ExpectedConditions.ElementExists(By.CssSelector("button[aria-label^='Send message']"))); var connections = driver.FindElementsByClassName("mn-connection-card"); var totalConnections = connections.Count; for (int i = 0; i < connections.Count; i++) { var connection = connections[i]; var card = new ConnectionCard(connection); driver.ExecuteScript("arguments[0].scrollIntoView()", connection); var received = new Events.User { AvatarUrl = card.MugshotUrl, Description = card.Occupation, Id = card.ProfileUrl.AsId <User>(Network.LinkedIn), KnownSince = card.ConnectedDate, Name = card.Name, Network = Network.LinkedIn }; connections = driver.FindElementsByClassName("mn-connection-card"); var responses = driver.ExecuteScript("return window.lresponses;"); driver.ExecuteScript("window.lresponses.clear();"); await SaveResponses(credential, sourceId, responses); } } catch (Exception e) { _logger.LogError(e, "Failed"); } finally { driver?.Quit(); } }
internal static UserCard FromUser(Events.User u) { if (u != null) { return new UserCard { AvatarUrl = ScaleMugshot(u.AvatarUrl), Id = u.Id, Network = "Yammer", Name = u.Name, Description = u.Description, } } ; return(new UserCard()); }