0

Following is my code:

 WebElement name = driver.findElement(By.name("firstName")).sendKeys(new String[] { "Jacob" });

I'm using Selenium 2.44 and Mozilla Firefox 33. Referring the above code, I'm getting a compile time error on sendKeys() function and eclipse is asking me to open the "Configure Build Path" window.
The Compiler Compliance Level for eclipse is 1.7.
Please help me resolving the error with sendKeys() function.

Bharat DEVre
  • 539
  • 3
  • 13

3 Answers3

0

Your Code is incorrect. Please refer following simplified code,

WebElement name = driver.findElement(By.name("firstName"));
           name.sendKeys(new String[] { "Jacob" });

Explanation of your code:

driver.findElement(By.name("firstName")).sendKeys(new String[] { "Jacob" });

This returns void not WebElement

Bharat DEVre
  • 539
  • 3
  • 13
  • Thank you for replying. Though both our codes are logically same and correct, your code doesn't seem to work too. It gives me the same error. Could you please suggest a different solution for the same? – Tabish Khan Jan 15 '16 at 13:12
  • If you observe carefully our codes are not equals .Above code working in my eclipse .Make sure you have added selenium dependency to maven – Bharat DEVre Jan 15 '16 at 13:20
  • Yes Maven is added and the code which you've suggested doesn't seem to work too. – Tabish Khan Jan 15 '16 at 13:25
0

Match the complier version of Eclipse and Maven. Both should atleast 1.6. Or refer to below stack:

Error when using sendKeys() with Selenium WebDriver Java.lang.CharSequence cannot be resolved

Community
  • 1
  • 1
Abhishek Yadav
  • 459
  • 5
  • 16
-3

You are passing an array of strings to sendKeys(), although a simple string would do:

WebElement name = driver.findElement(By.name("firstName"));
           name.sendKeys("Jacob");
Kim Homann
  • 3,042
  • 1
  • 17
  • 20
  • Thank you for replying. The simple way which you have suggested didn't work at first. Hence i went with this method. Could you please suggest a different solution for the same? – Tabish Khan Jan 15 '16 at 13:22
  • The first answer wasn't from me, that was a different person. What kind of error do you get on this solution? It should be syntactically correct. Maybe you should add an HTML snippet! – Kim Homann Jan 15 '16 at 16:39