繁体   English   中英

硒声明的软件包与预期的软件包不匹配

[英]selenium declared package doesn't match expected package

我靠硒。 我无法运行示例脚本。 请帮助我找出我做错了什么。 谢谢! 我的安装:JDK1.7.0._02 selenium-server-standalone-2.31.0.jar Eclipse IDE 3.7.0 Selenium IDE 1.9.0(Firefox插件)

当我单击代码1.中的包部分时,Eclipse指示以下错误消息。声明包org.openqa.selenium.example; 与预期的软件包Seletest1不匹配2.令牌软件包的语法错误,导入的预期Eclipse还建议将Test1.java移至软件包org.openqa.selenium.example

请建议我采取正确的措施,应该将org.openqa.selenium.example导入项目的构建路径中还是应该将Test1.java移入软件包中?

在哪里可以找到package-org.openqa.selenium.example的位置?

这是我从Google代码复制的代码,开始使用Selenium我的项目结构为SeleniumTest1> Src> SeleTet1

package SeleTest1;
package org.openqa.selenium.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Test1 
{
    public static void main(String[] args) 
    {
        // Create a new instance of the html unit driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new HtmlUnitDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
    }

}

当我执行代码时显示错误消息当我在Eclipse中运行代码时,收到以下错误消息:线程“ main” java.lang.Error中的异常:未解决的编译问题:方法中的sendKeys(CharSequence []) WebElement类型不适用于参数(字符串)

您的代码顶部有一个重复的包声明。 由于您的代码可能位于SeleTest1文件夹中, SeleTest1我将删除第二个( org.openqa.selenium.example )。

不需要您的程序包声明与所使用的框架之一匹配。

当您将selenmium IDE记录的测试用例导出为webdriver格式时,默认情况下,package语句将添加为

package org.openqa.selenium.example;

我们需要根据在Eclipse中创建的包名称对其进行修改。

因此,根据您的情况,您可以删除以下重复的行。

package org.openqa.selenium.example;

完成此修改后,您也不会收到第二个错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM