无法解决将 sendKeys() 与 Selenium WebDriver Java.lang.CharSequence 一起使用时的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24694171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error when using sendKeys() with Selenium WebDriver Java.lang.CharSequence cannot be resolved
提问by Viswanath
I have imported the following and still get an error when using sendKeys();
我已导入以下内容,但在使用时仍然出现错误 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.
注意:我在 Eclipse 中使用 Selenium WebDriver。
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");
指向线 myElement.sendKeys("text");
Can one of you let me know what is incorrect here.
你们中的一个人可以让我知道这里有什么不正确的。
采纳答案by Vignesh Paramasivam
You could try this, similar issue has been answered here #sendKeys Issue
你可以试试这个,这里已经回答了类似的问题#sendKeys Issue
myElement .sendKeys(new String[] { "text" }); //You could create a string array
or simply
或者干脆
myElement .sendKeys(new String { "text" });
回答by raj
This is because of your eclipse Editor.
这是因为您的 eclipse 编辑器。
Follow the steps below to overcome that error.
请按照以下步骤克服该错误。
- Right click on the java Project.
- Select Build Path >Configure Build Path.
- 右键单击 java 项目。
- 选择构建路径 > 配置构建路径。
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.
A.Java Build Path > Libraries - 这里的编辑器应该参考你机器上安装的版本。如果它指的是旧库文件,则将其删除并单击添加库并从列表中选择最新的 Jre 系统库。
B.Java Compiler. Here Compiler compliance level should be the latest/ the one installed on your machine.
B.Java 编译器。此处编译器合规性级别应该是您机器上安装的最新/最新级别。
回答by fahad
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.
当您使用 JDK8 时,您的编译器版本应该是 1.8,您只能使用最新的 eclipse 版本 - ECLIPSE LUNA 获得。另一种方法是将您的 JDK8 降级到 JDK7,它仍然可以工作。
回答by Kumrun Nahar Keya
I faced the same problem during using eclipse Kepler.
我在使用 eclipse Kepler 时遇到了同样的问题。
Problem domain:
My java compiler compliance levelwas 1.4
问题域:
我的 Java编译器合规性级别为1.4
Solution:
so using build path >> configure build path>> java compiler>> changed the compiler compliance levelto 1.7 or higher
解决方案:
所以使用构建路径>>配置构建路径>>java编译器>>将编译器合规级别更改为1.7或更高
This could solve the problem.
这可以解决问题。
回答by Ripon Al Wasim
It needs to upgrade the Compiler Compliance. For Eclipse: Follow the steps below:
它需要升级编译器合规性。对于 Eclipse:请按照以下步骤操作:
- Right click on your java project and select Build Path -> Click on Configure Build Path...
- In project properties window: Click/select Java Compilerat the left panel
- At the right panel: change the Compiler compliancelevel from 1.4 to 1.7 or higher
- Lastly Click on Apply and OK
- 右键单击您的 java 项目并选择 Build Path -> 单击 Configure Build Path...
- 在项目属性窗口中:单击/选择左侧面板中的Java Compiler
- 在右侧面板:将编译器合规性级别从 1.4更改为 1.7 或更高
- 最后点击应用和确定
回答by TUSH2
Check Eclipse version Eclipse 4.3 (Kepler) and above version need to upgrade JAVA JDK 1.8.
检查 Eclipse 版本 Eclipse 4.3 (Kepler) 及以上版本需要升级 JAVA JDK 1.8。
After installation just check Eclipse:build path >> configure build path>> java compiler>> changed the compiler compliance level is 1.8
安装后只需检查Eclipse:构建路径>>配置构建路径>>java编译器>>更改编译器合规级别为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.
注意:1. 我建议使用 Java JDK 1.8 版本和 Eclipse Eclipse 4.6 (Neon) 2. Selenium 3+ 版本 jar 文件仅支持 JAVA JDK 1.8 及以上版本。
回答by Venkata Sai Sumanth Vadakattu
Faced the same kind of issue.
遇到了同样的问题。
Issue got resolved on upgrading to Eclipse Lunaand then changing the compiler version to 1.8
问题在升级到Eclipse Luna然后将编译器版本更改为 1.8 时得到解决
Compiler version 1.8is not available with the previous version
编译器版本 1.8不适用于以前的版本
回答by Shyam Puram
Issue will get resolved on upgrading to Eclipse Luna and then changing the compiler version to 1.8
问题将在升级到 Eclipse Luna 然后将编译器版本更改为 1.8 后得到解决
Compiler version 1.8 is not available with the previous version
编译器版本 1.8 不适用于以前的版本
There you are getting The type java.lang.CharSequence error.
你会得到类型 java.lang.CharSequence 错误。