import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;

public class className {

    public static void main(String[] args) throws InterruptedException {
        WebDriver driver;
        System.setProperty("webdriver.geckodriver" , "F:\\geckodriver-v0.15.0-win64\\geckodriver.exe");
        driver = new FirefoxDriver();
        driver.findElement(By.id("<first field>")).click();

          //This line through the error
        WebElement a= driver.findElement(By.id("<id>")).sendKeys("<abc>");

        driver.findElement(By.id("<second field>")).click();
        driver.findElement(By.id("<field name")).sendKeys("<xyz>");
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


in this program, the following line throws an error as Type mismatch: cannot convert from void to WebElement.

New to automation. Help is greatly needed


This error is thrown because of the in the following line

WebElement a= driver.findElement(By.id("<id>")).sendKeys("<abc>");

You are declaring a variable of type WebElement here, but calling sendKeys() method which returns void. Remove the sendKeys() method call from the line.

Write the code like -

WebElement a = driver.findElement(By.id("<id>"));
  • I have one problem. The data is not getting entered in the username field. The login page opens correctly. But the username and password whatever i passed is not getting entered in it. I used the same program above. Please help – Indu Apr 23 '17 at 7:22
  • What is the error that you are getting?? I think it might be because the element is not yet visible and the script is trying to enter the text. Write the implicit wait statment at the top i.e. After defining driver = new ChromeDriver() – Avtar Krishna Jha Apr 23 '17 at 7:27
  • i'm not getting any error. The webpage in firefox is opening correctly. but the username and password is not getting entered in those fields. i used the same program mentioned above – Indu Apr 23 '17 at 7:55
  • This might be because your geckodriver might not be supporting the firefox version. Try updating the firefox version to latest and also the geckodriver. – Avtar Krishna Jha Apr 25 '17 at 7:24

Issue has already been resolved but still the issue that you will be getting is due to the firefox driver.

Trying using gecko driver and set the properties as:

System.setProperty("webdriver.gecko.driver" , "F:\\geckodriver-v0.15.0-win64\\geckodriver.exe");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.