0

sendKeys function is displaying following error in the code:

The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)

Error line code:

driver.findElement(By.name("username")).sendKeys("Bharat");

I'm importing following librariers:

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

Java Version: 1.8.0_281 Selenium: 3.141.59

Appreciate you help

J.F.
  • 13,927
  • 9
  • 27
  • 65
  • 1
    It wants an array of Strings instead. – Jems Jan 24 '21 at 22:59
  • According to [this](https://stackoverflow.com/a/23624169/13464279) answer you can try `driver.findElement(By.name("username")).sendKeys(new String[]{"Bharat"});`. But also check your compiler compliance level: look [this](https://stackoverflow.com/a/24103315/13464279) and [this](https://stackoverflow.com/a/34655130/13464279) – J.F. Jan 24 '21 at 23:29
  • Thanks Jems, that solved the problem. Cheers – Bharat Shori Jan 26 '21 at 10:51

1 Answers1

0

(I can't comment yet, so leaving this)

Can you provide more context

  • full stacktrace of the error
  • surrounding code/ the html of what you are referencing
  • what are you trying to accomplish

Browserstack says this is the way to send keys to an input field: https://www.browserstack.com/guide/sendkeys-in-selenium

  1. Make sure driver.findElement(By.name("username")) is actually the element name of the input field
  2. Set a breakpoint, and check driver.findElement(By.name("username")) gets the element you want
baumannalexj
  • 766
  • 1
  • 9
  • 20