Question

I've been playing with the Selenium C# framework and been trying to do a facebook login, but without any luck.

This is what i got so far (based on this post: Testing a Facebook Connect application using Selenium?). I can't get it to work though.

ISelenium sel = new DefaultSelenium("localhost", 4444, "*chrome", "http://facebook.com");
public void LoginWithEmailAndPassword(string email, string pass)
{
    sel.Start();
    sel.Open("http://www.facebook.com");
    sel.ClickAt("//img[\\@alt='Facebook']", "User clicks on Facebook Login");
    sel.WaitForPopUp("", "3000");
    sel.SelectPopUp("");
    sel.Type("email", email);
    sel.Type("pass", pass);
    sel.KeyPress("pass", "\\13");
    sel.SelectWindow("null");
}

So if someone could provide me with some sample code for how to do this, or guide me in the right direction, it would be appreciated.

Resolved

By using the record feature of the Firefox Selenium plugin I got the id's and the functions i needed to get it working. The login button seemed to require an XPath definition, which I also got from the Selenium IDE.

ISelenium sel = new DefaultSelenium("localhost", 4444, "*chrome", "http://facebook.com");
public void LoginWithEmailAndPassword(string email, string pass)
{
    sel.Start();
    sel.Open("/");
    sel.Type("id=email", email);
    sel.Type("id=pass", pass);
    sel.Click("//label[@id='loginbutton']/input");
}
Was it helpful?

Solution

Try use WebDriver:

IWebDriver driver = new FireFoxDriver();
driver.GoToUrl("www.facebook.com");

var element = driver.FindElement(By.Id("email"));
element.SendKeys(email);
...
element = driver.FindElement(By.Id("submit button id"));
element.Click();

This link could help you get start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top