1

I'm trying to input text into a username field. It appears to find an element, however SendKeys() errors stating that the element is not interactable. I'm already waiting until the element exists, so I wouldn't think its related to waiting. Here is my code:

Console.WriteLine("Hello, World!");
ChromeDriver cd = new 
ChromeDriver(@"C:\Users\xxx\Downloads\chromedriver_win32\");
cd.Url = @"https://connect.ramtrucks.com/us/en/login";
cd.Navigate();

WebDriverWait wait = new WebDriverWait(cd,TimeSpan.FromSeconds(10));
IWebElement e = wait.Until(ExpectedConditions.ElementExists(By.ClassName("analytics-login-username")));

e.SendKeys("[email protected]");

Any suggestions would be much appreciated :)

1 Answer 1

1

There are 2 thing you need to fix here:

  1. You are using locator that is not unique.
  2. You need to wait for element clickability, not just existence. I couldn't find element clickability case in C#, so element visibility can be used instead.
    So, instead of
IWebElement e = wait.Until(ExpectedConditions.ElementExists(By.ClassName("analytics-login-username")));

e.SendKeys("[email protected]");

Try this:

IWebElement e = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("input.analytics-login-username"))).SendKeys("[email protected]");
Sign up to request clarification or add additional context in comments.

2 Comments

Ahhh, makes sense. These changes worked. Thank you so much! I'm curious, how were you able to tell that locator wasn't unique?
The way to find locators is: open the page with Chrome, open dev tools with F12, Elements tab, use arrow to select elements. Control + F - write there the locator. It will show if such match exists and how many matches found. analytics-login-username class name will give you 2 matches while the first one is not the input you need, this element is not interactable. Simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.