简体   繁体   中英

Unable to click an input tag with Selenium Chrome driver

I'm running with the following packages:

"Selenium.Support" version="3.3.0" targetFramework="net40"

"Selenium.WebDriver" version="3.3.0" targetFramework="net40"

"Selenium.WebDriver.ChromeDriver" version="2.28.0" targetFramework="net40"

"WebDriver.ChromeDriver" version="26.14.313457.1" targetFramework="net40"

And in my test program I'm trying to log into morningstar.com but the clicking never works to submit the username/password. Any suggestions? I've seen may people online having issues trying to click. I've also tried IE and firefox and both didn't work for me.

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);
        }
    }
}

I've also tried using an Action, and the Javascript workaround like other answers online have suggested:

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

Any ideas, or is this a bug in selenium?

Click probably works fine, problem could be that your password field is not properly set because value will be stored after onFocus event is triggered and you are clicking on submit directly after you write text in your password field.

To test this, try to perform click() on username field after you set password. Something like this, I added two clicks:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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