0
votes

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?

1
I assume for <username> and <password> you are actually putting in the username and password strings? Also, what type of html elements are "Username" and "Password"? I am only asking because your code looks correct, so I am just wondering if there is any detail left out. - mmilleruva
What version of Selenium + Firefox? - Arran
Selenium 2.31.0 and firefox 3.6.12 (although would like it to work with multiple versions). Yes, I'm using the real strings for username and password, and the elements are <input type = "text"> and <input type = "password"> - user3355764
Not entirely sure v2.31 actually supports FF v3.6 since both are very old & out of date (have no evidence to back that up though). Why are you using an old version out of interest? You may try turning off native events though. - Arran
These are the only versions available on my office system. Thank you, turning off native events solved the problem!! - user3355764

1 Answers

0
votes

What error is it giving? If it's saying that the element doesn't exist, that means that your

FindElement(By.Id("Password"))

isn't working and you need to double check that the id of the element that you are trying to select is correct. Another issue may be that the password field is secured somehow from automated programs or that the field doesn't actually accept string input.