Website login Issue in Selenium ChromeDriver



  • I am login to a website using Selenium and ChromeDriver. But website login details are shown as incorrect every time. But I have manually logged into the site using Chrome browser easily.

    How do I login to the website using Selenium and ChromeDriver without issue?

    Code:

    IWebDriver driver = new ChromeDriver(service, options);
    driver.Navigate().GoToUrl("https://www.textnow.com/login");
    driver.FindElement(By.Name("username")).SendKeys("pankajsingh42@gmail.com");
    driver.FindElement(By.Name("password")).SendKeys("*********");
    driver.FindElement(By.Id("btn-login")).Click();
    

    Page example:

    enter image description here



  • The code looks like it could work, but maybe the page loads slow and you are trying to interact with an element that does not exist yet. Be sure you wait for the first element to be ready. I added a wait to your example.

    IWebDriver driver = new ChromeDriver(service, options);
    driver.Navigate().GoToUrl("https://www.textnow.com/login");
    
    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
    var username = wait.Until(f => f.FindElement(By.Name("username")));
    
    username.SendKeys("pankajsingh42@gmail.com");
    driver.FindElement(By.Name("password")).SendKeys("*********");
    driver.FindElement(By.Id("btn-login")).Click();
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2