无法使用Selenium Chrome驱动程序单击输入标记

时间:2017-04-03 04:53:31

标签: c# selenium

我正在使用以下软件包运行:

" Selenium.Support"版本=" 3.3.0" targetFramework =" net40"

" Selenium.WebDriver"版本=" 3.3.0" targetFramework =" net40"

" Selenium.WebDriver.ChromeDriver"版本=" 2.28.0" targetFramework =" net40"

" WebDriver.ChromeDriver"版本=" 26.14.313457.1" targetFramework =" net40"

在我的测试程序中,我尝试登录morningstar.com,但点击从不会提交用户名/密码。有什么建议?我见过网上的人可能会在尝试点击时遇到问题。我也试过IE和Firefox,两者都没有为我工作。

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using System.Threading;

namespace ConsoleApplication1
{

    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://www.morningstar.com/members/login.html");
            Thread.Sleep(5000);
            driver.FindElement(By.Id("uim-uEmail-input")).SendKeys("email");
            driver.FindElement(By.Id("uim-uPassword-input")).SendKeys("password");
            Thread.Sleep(1000);

            driver.FindElement(By.Id("uim-login-submit")).Click();
            Thread.Sleep(10000);
        }
    }
}

我也尝试过使用动作,并且像其他在线答案一样建议使用Javascript解决方法:

        ((IJavaScriptExecutor)(driver)).ExecuteScript("arguments[0].click();", driver.FindElement(By.Id("uim-login-submit")));

任何想法,或者这是硒中的错误?

1 个答案:

答案 0 :(得分:0)

点击可能工作正常,问题可能是您的密码字段未正确设置,因为在onFocus事件被触发后您将存储值,并且您在密码字段中写入文本后直接单击提交。< / p>

要对此进行测试,请在设置密码后尝试在用户名字段中执行click()。像这样,我添加了两次点击:

driver.FindElement(By.Id("uim-uEmail-input")).SendKeys("email");
driver.FindElement(By.Id("uim-uPassword-input")).Click();
driver.FindElement(By.Id("uim-uPassword-input")).SendKeys("password");
driver.FindElement(By.Id("uim-uEmail-input")).Click();