selenium.WebElement.sendKeys()出错 [英] Error with selenium.WebElement.sendKeys()

查看:1268
本文介绍了selenium.WebElement.sendKeys()出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整理一个小应用程序,在Magento网站上使用Selenium WebDriver在Java中执行自动检出。我正在努力学习Java,所以我坚持用Java来解决这个问题,而不是改用Ruby或Python。

I am putting together a small app to perform automated checkouts on a Magento site, using Selenium WebDriver in Java. I'm working on learning Java, so I'm adamant on getting this figured out with Java, and not switching to Ruby or 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()行确认我得到了我希望从页面中获取该元素。

My getName() line confirms that I am getting the element that I want from the page.

我在编译时遇到此错误:

I'm getting this error when compiling:


[INFO]编译失败
/seleniumMagento/src/main/java/com/huuginn/seleniumMagento/App.java:[25,13]
sendKeys(java.lang.CharSequence .. 。)org.openqa.selenium.WebElement
不能应用于(java.lang.String)

[INFO] Compilation failure /seleniumMagento/src/main/java/com/huuginn/seleniumMagento/App.java:[25,13] sendKeys(java.lang.CharSequence...) in org.openqa.selenium.WebElement cannot be applied to (java.lang.String)

sendKeys is期望实现CharSequence的类型的参数(java.lang.String符合条件),所以我不明白为什么我会收到此错误。

sendKeys is expecting a parameter of a type that implements CharSequence (java.lang.String qualifies as such), so I don't understand why I'm getting this error.

I我正在使用Java 1.6和Selenium 2.19,使用Maven进行构建。

I am using Java 1.6, and Selenium 2.19, doing my build with Maven.

推荐答案

我在调用<$ c时遇到了类似的问题$ C>的SendKeys()。问题通常是签名是var-ary,即 CharSequence ... 而不是 CharSequence

I have had similar problems with calling sendKeys(). The problem usually is, that the signature is a var-ary, that is CharSequence... instead of just CharSequence.

当然这不应该是Java 6的问题。我的猜测是你的maven编译使用不同的编译器设置。无论如何,您可以将代码更改为

Of course this should not be a problem with Java 6. My guess would be that your maven compile uses a different compiler setting. Anyways you could change your code to

searchField.sendKeys(new String[] { "sample" });

以帮助诊断问题。

这篇关于selenium.WebElement.sendKeys()出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆