用C#登录Selenium [英] Facebook Login with Selenium for C#

查看:237
本文介绍了用C#登录Selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩Selenium C#框架,并试图做一个Facebook登录,但没有任何运气。

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

这是我到目前为止基于此信息:使用Selenium测试Facebook Connect应用程序? / A>)。

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.

已解决

通过使用Firefox Selenium插件的记录功能,我得到了id和我需要的功能来使其工作。登录按钮似乎需要一个XPath定义,我也从Selenium IDE获取。

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


推荐答案

尝试使用WebDriver: p>

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();

这个链接可以帮助您开始。

这篇关于用C#登录Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆