繁体   English   中英

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

[英]Unable to click an input tag with Selenium Chrome driver

我正在运行以下软件包:

“ 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")));

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

单击可能工作正常,问题可能是您的密码字段未正确设置,因为在onFocus事件后会存储值,并且您在密码字段中输入文本后直接单击提交。

要对此进行测试, click()在设置密码后尝试对用户名字段执行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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM