private void BindUserInfo() { //BindUserInfoByApi(); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); UserListInfo.Add(new FbpageInboxUserInfo { InboxUserName = "******" }); }
private void LoginCommandHandler(object obj) { //string url1 = // "https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558"; //// string url = "https://go.developer.ebay.com/api-call-limits"; //var Client = new HttpClient(); //Task<string> t = Client.GetStringAsync(url1); //string s = t.Result; //Console.WriteLine(s); try { string appStartupPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // string appStartupPath = Path.Combine(Environment.CurrentDirectory); const string url = "https://en-gb.facebook.com/login/"; _options.AddArgument("--disable-notifications"); _options.AddArgument("--disable-extensions"); _options.AddArgument("--test-type"); //options.AddArgument("--headless"); _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(TextBoxUserEmail.Text); } ReadOnlyCollection <IWebElement> passwordElement = ChromeWebDriver.FindElements(By.Id("pass")); if (passwordElement.Count > 0) { passwordElement[0].SendKeys("1234567#rk"); //passwordElement[0].SendKeys(TextBox_Password.Text); } ReadOnlyCollection <IWebElement> signInElement = ChromeWebDriver.FindElements(By.Id("loginbutton")); if (signInElement.Count > 0) { signInElement[0].Click(); ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages"); ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558"); Thread.Sleep(2000); string pageSource = ChromeWebDriver.PageSource; HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(pageSource); HtmlNodeCollection imgNode = htmlDocument.DocumentNode.SelectNodes("//*[@id='u_0_t']/div/div/div/table/tbody/tr/td[1]/div/div[2]/div/div[1]/div/div/div/div/div/div/img"); if (imgNode != null) { foreach (var imgNodeItem in imgNode) { getimgurl = imgNodeItem.Attributes["src"].Value.Replace(";", "&"); myqueue.Enqueue(getimgurl); } } var listNodeElements = htmlDocument.DocumentNode.SelectNodes( "//div[@class='_4ik4 _4ik5']"); if (listNodeElements != null) { for (int i = 0; i < listNodeElements.Count; i++) { if (i % 2 == 0) { LstItemUserName = listNodeElements[i].ChildNodes[0].InnerText; var imgUrl = myqueue.Dequeue(); UserListInfo.Add(new FbpageInboxUserInfo() { InboxUserName = LstItemUserName, InboxUserImage = imgUrl }); } } } } } catch (Exception) { throw; } }