I have been using selenium in a windows form in C# to enter a username and password on a page and click login, then to perform some more actions. This works fine, but a later step will involve measuring the time it takes for a firefox dialog box to appear, which I don't think can be done with selenium. I am therefore trying to migrate to webdriver. When I try to enter the username and password with webdriver.sendkeys, it puts the cursor into the correct box but does not enter any text. My selenium code was:
namespace Project1
{
public partial class Form1 : Form
{
public Form1()
{
Process.Start("D:\\startSelenium.bat");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ISelenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", <baseURL>);
selenium.Start();
selenium.Open(<loginpage>);
selenium.Type("id=UserName", <username>);
selenium.Type("id=Password", <password>);
selenium.Click("css=input.button");
selenium.WaitForPageToLoad("40000");
...
The webdriver code I am using is:
namespace Project2
{
public partial class Form1 : Form
{
public Form1()
{
Process.Start("D:\\startSelenium2.bat");
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FirefoxProfile profile = new FirefoxProfile(C:\\Selenium");
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl(<loginpage>);
driver.FindElement(By.Id("UserName")).Clear();
driver.FindElement(By.Id("UserName")).SendKeys(<username>);
driver.FindElement(By.Id("Password")).Clear();
driver.FindElement(By.Id("Password")).SendKeys(<password>);
...
It is getting stuck at the line
driver.FindElement(By.Id("UserName")).SendKeys(<username>);
What am I doing wrong?