0

I can't fill the password in the password field. I am not sure where am I wrong. The current code that I am using is filling the password in the same field with the email address. I am using the following code:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
 namespace Cube
 {
  [TestClass]
  public class Setup
  {
    static IWebDriver driverGC;

    [AssemblyInitialize]
    public static void SetUp(TestContext context)
    {
        driverGC = new ChromeDriver();
    }

    [TestMethod]
    public void TestChromeDriver()
    {
        driverGC.Navigate().GoToUrl("https://google.com");
        driverGC.FindElement(By.Id("gb_70")).Click();
        driverGC.FindElement(By.CssSelector("#identifierId.whsOnd.zHQkBf")).SendKeys("mail@gmail.com");
        driverGC.FindElement(By.CssSelector("#identifierId.whsOnd.zHQkBf")).Click();
        driverGC.FindElement(By.CssSelector(".whsOnd.zHQkBf")).SendKeys("password123");
        driverGC.FindElement(By.CssSelector(".whsOnd.zHQkBf")).Click();
        driverGC.Navigate().GoToUrl("https://google.com");
    }
}
      }

Thanks!

  • Possible duplicate of [Selenium test scripts to login into google account through new ajax login form](https://stackoverflow.com/questions/45953043/selenium-test-scripts-to-login-into-google-account-through-new-ajax-login-form) – undetected Selenium Feb 25 '18 at 12:28

3 Answers3

0

I'm using the following code to detect the WebElements for login in Gmail, to avoid timing issues you have to add some (Explicit) waiting before calling the method.

public static void LoginGmail (IWebDriver driver, string email, string password )
    {          
        var loginBox = driver.FindElement(By.Id("Email"));
        loginBox.SendKeys(email);

        var nextBtn = driver.FindElement(By.Id("next"));
        nextBtn.Click();

        var pwBox = driver.FindElement(By.Id("Passwd"));
        pwBox.SendKeys(password);

        var signinBtn = driver.FindElement(By.Id("signIn"));
        signinBtn.Click();
    }
Frank
  • 831
  • 1
  • 11
  • 23
0

Use this (working code):

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.PageObjects;

public class GoogleLoginPage : BasePageObject
    {
        public GoogleLoginPage(IWebDriver driver) : base(driver) { }

        const string _url = "https://accounts.google.com/ServiceLogin";

        [FindsBy(How = How.Id, Using = "identifierId")]
        IWebElement GoogleInput { get; set; }

        [FindsBy(How = How.CssSelector, Using = "[id='identifierNext']")]
        IWebElement GoogleButton { get; set; }

        [FindsBy(How = How.CssSelector, Using = "[name='password']")]
        IWebElement GooglePassInput { get; set; }

        [FindsBy(How = How.CssSelector, Using = "[id='passwordNext']")]
        IWebElement GooglePassButton { get; set; }

        public void LoginAccountGoogleSitePage()
        {
            _driver.Navigate().GoToUrl(_url);
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
            wait.Until(d => GoogleLoginInput.Displayed);
            GoogleInput.SendKeys("mail@gmail.com");
            GoogleButton.Click();
            GooglePassInput.SendKeys("password123");
            GooglePassButton.Click();
        }

    }
Quiver
  • 1
0

So, I am using the code below for another site. You can use it as an example and use some parts in your work.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace Auto_Login_Bot
{
    public class Program
    {
        static void Main()
        {
            IWebDriver driverGC = new ChromeDriver();

            const string _url = "site-name";

            const string usr = "";
            const string pass = "";

            driverGC.Navigate().GoToUrl(_url);
            IWebElement Login = driverGC.FindElement(By.Id("authorization-email-input"));
            IWebElement Password = driverGC.FindElement(By.Id("authorization-password-input"));
            IWebElement LoginButton = driverGC.FindElement(By.Id("authorization-submit-button"));
            Login.SendKeys(usr);
            Password.SendKeys(pass);
            LoginButton.Click();
        }
    }
}