0

I am using Selenium writing in Java by VS Code.

I am unable to compile this line of code since there is a red line under the method sendKeys.

The line of code is:

driver.findElement(By.xpath("xpath")).sendKeys("Cologne");

Error is shown as:

The method sendKeys(String) is undefined for the type ByJava(67108964)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Have you imported `Keys`? If yes, what is the exact error? – 0buz Feb 17 '20 at 15:19
  • Yes. The exact error is: The method sendKeys(String) is undefined for the type ByJava(67108964). – Farbod Alidaei Feb 17 '20 at 15:23
  • When I change the line using cssSelector instead of xpath to reach the WebElement the problem get fixed automatically. why is that? – Farbod Alidaei Feb 17 '20 at 15:30
  • Based on the error message seems 'import org.openqa.selenium.WebElement' and/or 'import org.openqa.selenium.By' are missing. If all imports are OK check dependecies and libs. – pburgr Feb 17 '20 at 16:12

1 Answers1

0

This error message...

The method sendKeys(String) is undefined for the type ByJava(67108964)

...implies that there is a configuration issue within the environmental settings.


As per this discussion Solution for sendkeys(CharSequence) in Selenium while you start writing code using Selenium's client, at times your project Java Compiler version will be below v1.5 and sendKeys() will won't be read by the compiler. In these cases you need to upgrade the compiler version to 1.5 and above.

JavaCompiler


Solution

You need to make the following changes:

  • Change the compiler version from old version to 1.5 or greater.
  • Additionally, you may need to go to Java Build Path -> Libraries -> Select Java SE 1.8 (if Java 8 is installed)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for explaining but if that is the problem why sendKeys is recognized after using cssSlector instead of xpath? I mean, if there is a problem with configuration, sendKeys should not be recognized anyway; neither by the use of xpath nor cssSelector. – Farbod Alidaei Feb 19 '20 at 14:43