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)
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
Vini R
  • 1
  • 2
  • 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? – Julian Mar 15 '15 at 08:21
  • Thank you for your answer. I am using Eclipse helios IDE. Complier compliance level is 1.4 . But , still it is not working. – Vini R Mar 15 '15 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. – Julian Mar 16 '15 at 04:36

4 Answers4

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?

Community
  • 1
  • 1
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
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

Community
  • 1
  • 1
Vini R
  • 1
  • 2
  • 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. – Julian Apr 17 '15 at 23:05
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

Naveed
  • 1
-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);
tanghao
  • 4,073
  • 2
  • 13
  • 17
  • 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 – Vini R Mar 15 '15 at 15:45