C# Selenium Webdriver sendkeys()不工作

C# Selenium Webdriver sendkeys()不工作,c#,selenium-webdriver,C#,Selenium Webdriver,我一直在用C语言在windows窗体中使用selenium在页面上输入用户名和密码,然后单击login,然后执行更多操作。这很好,但后面的步骤将涉及到测量firefox对话框出现所需的时间,我认为selenium无法做到这一点。因此,我正在尝试迁移到webdriver。当我尝试使用webdriver.sendkeys输入用户名和密码时,它会将光标放在正确的框中,但不会输入任何文本。我的代码是: namespace Project1 { public partial class Form1

我一直在用C语言在windows窗体中使用selenium在页面上输入用户名和密码,然后单击login,然后执行更多操作。这很好,但后面的步骤将涉及到测量firefox对话框出现所需的时间,我认为selenium无法做到这一点。因此,我正在尝试迁移到webdriver。当我尝试使用webdriver.sendkeys输入用户名和密码时,它会将光标放在正确的框中,但不会输入任何文本。我的代码是:

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");
                ...
我使用的webdriver代码是:

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>);
                ...
它在线路上卡住了

driver.FindElement(By.Id("UserName")).SendKeys(<username>);

我做错了什么?

它产生了什么错误?如果它说元素不存在,那意味着

FindElement(By.Id("Password"))

不工作,需要再次检查您尝试选择的元素的id是否正确。另一个问题可能是密码字段以某种方式受到自动程序的保护,或者该字段实际上不接受字符串输入。

我假设为,而您实际上是在输入用户名和密码字符串?另外,用户名和密码是什么类型的html元素?我之所以这么问是因为你的代码看起来是正确的,所以我只是想知道是否有任何细节遗漏。Selenium+Firefox的哪个版本?Selenium 2.31.0和Firefox 3.6.12,尽管我希望它能与多个版本一起工作。是的,我使用真正的字符串作为用户名和密码,元素并不完全确定v2.31是否真的支持ffv3.6,因为这两个版本都非常陈旧&尽管已经过时,但没有证据支持这一点。为什么出于兴趣而使用旧版本?不过,您可以尝试关闭本机事件。这些是我的office系统上唯一可用的版本。谢谢,关闭本机事件解决了问题!!