Facebook的登录与硒的C# [英] Facebook Login with Selenium for C#

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

问题描述

我一直在玩的硒C#框架,并一直在努力做一个Facebook登录,但没有任何运气。



这是我走到这一步(根据这篇文章:测试用Selenium一个Facebook Connect应用程序)。我不能让它工作,虽然。

  ISelenium SEL =新DefaultSelenium(本地主机,4444,*铬 http://facebook.com); 
公共无效LoginWithEmailAndPassword(字符串email,字符串传递)
{
sel.Start();
sel.Open(http://www.facebook.com);
sel.ClickAt(// IMG [\\ @ ALT ='Facebook的'],在Facebook上登录用户点击);
sel.WaitForPopUp(,3000);
sel.SelectPopUp();
sel.Type(邮件,邮件);
sel.Type(通,通);
sel.KeyPress(通,\\13);
sel.SelectWindow(空);
}



因此,如果有人能为我提供如何做到这一点的一些示例代码,或指导我在正确的方向,我们将不胜感激。



解决



通过使用Firefox的插件硒我拿到身份证的,我需要得到它的工作职能的记录功能。登录按钮似乎需要一个XPath的定义,这也是我从硒IDE了。

  ISelenium SEL =新DefaultSelenium(本地主机,4444,*铬,http://facebook.com); 
公共无效LoginWithEmailAndPassword(字符串email,字符串传递)
{
sel.Start();
sel.Open(/);
sel.Type(ID =邮件,邮件);
sel.Type(ID =通行证,通过);
sel.Click(//标签[@ ID ='loginbutton'] /输入);
}


解决方案

尝试使用webdriver的:

  IWebDriver司机=新FireFoxDriver(); 
driver.GoToUrl(www.facebook.com);

VAR元= driver.FindElement(By.Id(电子邮件));
element.SendKeys(电子邮件);

元素= driver.FindElement(By.Id(提交按钮ID));
element.Click();

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


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

解决方案

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.

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

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