Using BrowserSession and HtmlAgilityPack to login to Facebook through .NET

后端 未结 6 1419
灰色年华
灰色年华 2020-12-05 08:26

I\'m trying to use Rohit Agarwal\'s BrowserSession class together with HtmlAgilityPack to login to and subsequently navigate around Facebook.

I\'ve previously manage

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 08:46

    Sorry, I don't know much about the HTML agility pack or BrowserSession class you've mentioned. But I did try the same scenario with HtmlUnit and it working just fine. I'm using a .NET wrapper (the source code of which can be found here and is explained a bit more here), and here's the code I've used (some details removed to protect the innocent):

    var driver = new HtmlUnitDriver(true);
    driver.Url = @"http://www.facebook.com/login.php";
    
    var email = driver.FindElement(By.Name("email"));
    email.SendKeys("some@email.com");
    
    var pass = driver.FindElement(By.Name("pass"));
    pass.SendKeys("xxxxxxxx");
    
    var inputs = driver.FindElements(By.TagName("input"));
    var loginButton = (from input in inputs
                       where input.GetAttribute("value").ToLower() == "login"
                       && input.GetAttribute("type").ToLower() == "submit"
                       select input).First();
    loginButton.Click();
    
    driver.Url = @"https://m.facebook.com/profile.php?id=1111111111";
    Assert.That(driver.Title, Is.StringContaining("Title of page goes here"));
    

    Hope this helps.

提交回复
热议问题