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?


IWebDriver driver = new ChromeDriver(service, options);

Page example:

enter image description here

  • 2
  • 1
    Pankaj, could you share the HTML of the login page, alongside a screenshot of it and the code you have already written? – João Farias Jun 25 '19 at 8:50
  • can you explain the scenario with more details for this issue(if you have code attach with this pls add it), So that we can figure that out? – Pavan N Jun 25 '19 at 9:29
  • IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("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(); – Pankaj Jun 25 '19 at 10:09
  • What is the exact error you are getting? I have answered with a common error, but without the error it could be anything. – Niels van Reijmersdal Jun 26 '19 at 15:25

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

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var username = wait.Until(f => f.FindElement(By.Name("username")));

  • I think it's guessing not answering the question. Maybe there is no focus on the input form? Advanced CSS may cause some troubles. – Bulat Jun 27 '19 at 9:29
  • @Bulat Maybe not answering the original question, but it could help others visiting this page with a similar issue. I also added a comment for more info on the error, than I will rewrite the answer :) – Niels van Reijmersdal Jun 27 '19 at 15:53

Like Niels said above, it could be the timing issue. You might wanna wait until the element exists in the page and then do the stuff. Like you can make a function called WaitUntilElementIsVisible, and call that function before you find any element in the page. Will be easier for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.