Error when using sendKeys() with Selenium WebDriver Java.lang.CharSequence cannot be resolved

41,583

Solution 1

You could try this, similar issue has been answered here #sendKeys Issue

myElement .sendKeys(new String[] { "text" }); //You could create a string array 

or simply

myElement .sendKeys(new String { "text" });

Solution 2

It needs to upgrade the Compiler Compliance. For Eclipse: Follow the steps below:

  1. Right click on your java project and select Build Path -> Click on Configure Build Path...
  2. In project properties window: Click/select Java Compiler at the left panel
  3. At the right panel: change the Compiler compliance level from 1.4 to 1.7 or higher
  4. Lastly Click on Apply and OK

enter image description here

Solution 3

I faced the same problem during using eclipse Kepler.

Problem domain:
My java compiler compliance level was 1.4

Solution:
so using build path >> configure build path>> java compiler>> changed the compiler compliance level to 1.7 or higher

This could solve the problem.

Share:
41,583
Viswanath
Author by

Viswanath

Updated on January 19, 2020

Comments

  • Viswanath
    Viswanath over 4 years

    I have imported the following and still get an error when using sendKeys();

    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.*;
    import org.testng.Assert;
    import org.openqa.selenium.WebDriver;
    

    Note: I am using Selenium WebDriver with Eclipse.

    The sample code is as below.

    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.*;
    import org.testng.Assert;
    import org.openqa.selenium.WebDriver;
    
    public class Practice {
    
        public static void main(String[] args)
          {
    
            WebDriver driver = new FirefoxDriver();
            String baseUrl = "http://www.facebook.com";
    
            String tagName="";
            driver.get(baseUrl);
            tagName = driver.findElement(By.id("email")).getTagName();
            System.out.println("TagName: "+tagName);    
            WebElement myElement = driver.findElement(By.id("username"));
            myElement.sendKeys("text");
          }
    }
    

    I received an error stating

    The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
    

    Pointing at the line myElement.sendKeys("text");

    Can one of you let me know what is incorrect here.

  • Viswanath
    Viswanath almost 10 years
    Thanks for the info. the line "myElement .sendKeys(new String { "text" });" worked with JRE7. However, when I switch the JRE to 8 it throws The method sendKeys(CharSequence[]) from the type WebElement refers to the missing type CharSequence. Have you experienced this before?
  • McTrafik
    McTrafik over 9 years
    I'm getting the same issue with .contains(CharSequence...) when switching from 1.7 to 1.8.
  • Ripon Al Wasim
    Ripon Al Wasim over 8 years
    What is the difference between String and String array in this case? It needs to pass a String as parameter in sendKeys method. It's better to pass simple and single String rather than array of Strings.