Viswanath
Viswanath

Reputation: 87

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

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.

Upvotes: 4

Views: 45438

Answers (8)

Shyam Puram
Shyam Puram

Reputation: 1

Issue will get resolved on upgrading to Eclipse Luna and then changing the compiler version to 1.8

Compiler version 1.8 is not available with the previous version

There you are getting The type java.lang.CharSequence error.

Upvotes: 0

Faced the same kind of issue.

Issue got resolved on upgrading to Eclipse Luna and then changing the compiler version to 1.8

Compiler version 1.8 is not available with the previous version

Upvotes: 0

TUSH2
TUSH2

Reputation: 29

Check Eclipse version Eclipse 4.3 (Kepler) and above version need to upgrade JAVA JDK 1.8.

After installation just check Eclipse: build path >> configure build path>> java compiler>> changed the compiler compliance level is 1.8

Note: 1. I suggest use Java JDK 1.8 version and Eclipse Eclipse 4.6 (Neon) 2. Selenium 3+ version jar file supported JAVA JDK 1.8 and above version only.

Upvotes: 0

Kumrun Nahar Keya
Kumrun Nahar Keya

Reputation: 537

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.

Upvotes: 1

Ripon Al Wasim
Ripon Al Wasim

Reputation: 37756

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

Upvotes: 2

fahad
fahad

Reputation: 389

As you are using JDK8, your compiler version should be 1.8 which you can get only with latest eclipse version - ECLIPSE LUNA. Alternate way is to downgrade your JDK8 to JDK7 and it will still work.

Upvotes: 0

raj
raj

Reputation: 41

This is because of your eclipse Editor.

Follow the steps below to overcome that error.

  1. Right click on the java Project.
  2. Select Build Path >Configure Build Path.

Here there are two things you need to check

A.Java Build Path > Libraries- Here editor should refer the version installed on your machine. If it's referring the old library files then remove it and click on Add Library and select the latest Jre system library from the List.

B.Java Compiler. Here Compiler compliance level should be the latest/ the one installed on your machine.

Upvotes: 0

Vignesh Paramasivam
Vignesh Paramasivam

Reputation: 2470

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" });

Upvotes: 2

Related Questions