繁体   English   中英

Facebook用Selenium登录C#

[英]Facebook Login with Selenium for C#

我一直在玩Selenium C#框架并且一直在尝试登录facebook,但没有运气。

这是我到目前为止所得到的(基于这篇文章: 使用Selenium测试Facebook Connect应用程序? )。 我不能让它工作。

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");
}

因此,如果有人可以为我提供一些如何执行此操作的示例代码,或者指导我朝正确的方向发展,那么我们将不胜感激。

解决

通过使用Firefox Selenium插件的记录功能,我获得了id和我需要的功能才能使它工作。 登录按钮似乎需要XPath定义,我也从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");
}

尝试使用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();

链接可以帮助您开始。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM