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
835 views
in Technique[技术] by (71.8m points)

eclipse - 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.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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


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

...