[英]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.