0

I am trying to automate gmail login.

When I enter the text in username input box using sendKeys() it is throwing an exception.

My code:

WebElement userName =   driver.findElement(By.id("Email"));
userName.sendKeys("tutorial");

Exception:

Error:The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String) at com.gmail.test.Gmaillogin.main(Gmaillogin.java:65)
3
  • Based on that snippet, it should work. A String is a CharSequence so passing in a string literal is absolutely the correct thing to do with that method. Perhaps providing a bit more of the surrounding code might reveal more? Edit: Also, what IDE are you using, and what is it's compiler level? Commented Mar 15, 2015 at 8:21
  • Thank you for your answer. I am using Eclipse helios IDE. Complier compliance level is 1.4 . But , still it is not working. Commented Mar 15, 2015 at 15:52
  • Try changing your compiler level to 1.7. The older java versions have differences in their features which can sometimes product unexpected results. Commented Mar 16, 2015 at 4:36

4 Answers 4

0

It's tell you that the sendKeys method get only CharSequence[] type. You have to create CharSequence[] and insert to it your value and use it within sendKeys method.

See this for using CharSequence: How to convert a String to CharSequence?

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you guys for helping me out. I am able to solve above problem.

Code that worked: userName.sendKeys(new String[]{"tutorial"});

For further details please see this link : Error when using sendKeys() with Selenium WebDriver Java.lang.CharSequence cannot be resolved

1 Comment

While this may work, I don't think that this is a good solution. It's typically bad practice to instantiate a String using new String(""). String literals not working implies that theres some underlying problem, and this solution seems to just subvert it. Have you tried experimenting with a newer compiler compliance? I've read before of other people having a similar issue using 1.4 as their compiler level. But moving up to a newer one fixed it. Even if you're restricted to 1.4, knowing if it works with 1.6 or 1.7 would help to explain the cause. That's the one thing I can think of.
0

Just check and update the Project language level to SDK Default(IntelliJ, not sure about eclipse) under your Project settings, it worked for me.

Thanks

Comments

-1

SendKeys method input should be CharacterSequence array but not String. But in Java, String is equal to a CharSequence. So you can do as following way

WebElement userName =   driver.findElement(By.id("Email"));
CharacterSequence[] cs = new String[]{"tutorial"};
userName.sendKeys(cs);

1 Comment

When i tried above code : WebElement userName = driver.findElement(By.id("Email")); CharacterSequence[] cs = new String[]{"tutorial"}; userName.sendKeys(cs); Exception: Exception in thread "main" java.lang.Error: Unresolved compilation problems: Characters Sequence can not be resolved

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.