[英]sendKeys method throwing an error in selenium like"The method sendKeys(char sequence[] )in the type webelement is not applicable for the string"
[英]Error with selenium.WebElement.sendKeys()
我正在整理一个小应用程序,使用Java中的Selenium WebDriver在Magento站点上执行自动检出。 我正在努力学习Java,所以我坚持用Java来解决这个问题,而不是改用Ruby或Python。
package com.huuginn.seleniumMagento;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* selenium app for completing checkout in magento
*
*/
public class App
{
public static void main( String[] args )
{
// MagentoCatalog c = new MagentoCatalog();
WebDriver driver = new FirefoxDriver();
driver.get("http://plmkt.huuginn.com/");
WebElement searchField = driver.findElement(By.id("search"));
System.out.println(searchField.getClass().getName());
searchField.clear();
searchField.sendKeys("sample");
searchField.submit();
}
}
我的getName()行确认我从页面获取了我想要的元素。
编译时我收到此错误:
[INFO]编译失败/seleniumMagento/src/main/java/com/huuginn/seleniumMagento/App.java:[25,13]在org.openqa.selenium.WebElement中的sendKeys(java.lang.CharSequence ...)不能应用于(java.lang.String)
sendKeys期望一个实现CharSequence的类型的参数(java.lang.String符合条件),所以我不明白为什么我得到这个错误。
我正在使用Java 1.6和Selenium 2.19,使用Maven进行构建。
调用sendKeys()
遇到了类似的问题。 问题通常是,签名是一个变量,即CharSequence...
而不仅仅是CharSequence
。
当然这应该不是Java 6的问题。我的猜测是你的maven编译使用不同的编译器设置。 无论如何,您可以将代码更改为
searchField.sendKeys(new String[] { "sample" });
帮助诊断问题。
在创建项目时,请确保选择“使用执行环境JRE:JavaSE-1.6。您可以在没有任何Sendkeys错误的情况下成功执行测试.100%它将起作用。
我发现了解决这个问题的另一种方法。 我没有指定要编译的Java版本,因此Maven正在编译旧版本。 我把它添加到我的pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
这允许我在sendKeys()中只有一个文字字符串“SAMPLE”,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.