Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

Selenium with Java - error in using sendKeys() function

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

question from:https://stackoverflow.com/questions/65876917/selenium-with-java-error-in-using-sendkeys-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

(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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...