4

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.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Viswanath
  • 87
  • 2
  • 3
  • 6

8 Answers8

2

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" });
Community
  • 1
  • 1
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57
  • 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? – Viswanath Jul 14 '14 at 06:40
  • I'm getting the same issue with .contains(CharSequence...) when switching from 1.7 to 1.8. – McTrafik Jan 08 '15 at 06:39
  • 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. – Ripon Al Wasim Jan 07 '16 at 12:54
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

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
1

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.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
0

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.

raj
  • 41
  • 8
0

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.

fahad
  • 389
  • 2
  • 12
0

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.

TUSH2
  • 29
  • 8
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

0

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.