2017-04-03 68 views
0

输入标签,我用下面的软件包运行:无法点击硒铬司机

“Selenium.Support”版本=“3.3.0” targetFramework =“net40”

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

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

+0

请告诉我们什么是即将出现的错误 – Sandeep

回答

0

点击可能工作正常,问题可能是您的密码字段设置不正确,因为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(); 
+0

不幸的是,这并没有奏效。 – sqenixs