【问题标题】:Unable to click an input tag with Selenium Chrome driver无法使用 Selenium Chrome 驱动程序单击输入标签
【发布时间】:2017-04-03 04:53:30
【问题描述】:

我正在使用以下软件包:

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

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

"Selenium.WebDriver.ChromeDriver" version="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);
        }
    }
}

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

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

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

【问题讨论】:

  • 请告诉我们即将发生的错误

标签: c# selenium


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多