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.

2

3 Answers 3

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

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

3 Comments

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?
If you observe carefully our codes are not equals .Above code working in my eclipse .Make sure you have added selenium dependency to maven
Yes Maven is added and the code which you've suggested doesn't seem to work too.
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

Comments

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

2 Comments

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?
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!

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.