简体   繁体   English

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

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

I am leaning selenium. 我靠硒。 I have trouble to run a sample script. 我无法运行示例脚本。 Please help me to figure out what I did wrong. 请帮助我找出我做错了什么。 Thanks! 谢谢! My installations: JDK1.7.0._02 selenium-server-standalone-2.31.0.jar Eclipse IDE 3.7.0 Selenium IDE 1.9.0 (Firefox plugin) 我的安装:JDK1.7.0._02 selenium-server-standalone-2.31.0.jar Eclipse IDE 3.7.0 Selenium IDE 1.9.0(Firefox插件)

Eclipse indicates the following error message when I click on the package section in the code 1.the declared the package org.openqa.selenium.example; 当我单击代码1.中的包部分时,Eclipse指示以下错误消息。声明包org.openqa.selenium.example; doesn't match expected package Seletest1 2. syntax error on token package, imported expected Eclipse also suggested move Test1.java to package 'org.openqa.selenium.example 与预期的软件包Seletest1不匹配2.令牌软件包的语法错误,导入的预期Eclipse还建议将Test1.java移至软件包org.openqa.selenium.example

Please suggest the right action for me to take, should I imported org.openqa.selenium.example into the build path of my project or should I move Test1.java into the package? 请建议我采取正确的措施,应该将org.openqa.selenium.example导入项目的构建路径中还是应该将Test1.java移入软件包中?

where Can I find out the location of the package-org.openqa.selenium.example? 在哪里可以找到package-org.openqa.selenium.example的位置?

Here is my code copied from Google code get started with Selenium my project structure SeleniumTest1>Src>SeleTet1 这是我从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());
    }

}

The error message showed when I execute the code When I run the code in Eclipse, I received the following error message: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String) 当我执行代码时显示错误消息当我在Eclipse中运行代码时,收到以下错误消息:线程“ main” java.lang.Error中的异常:未解决的编译问题:方法中的sendKeys(CharSequence []) WebElement类型不适用于参数(字符串)

You have a duplicate package declaration on the top of your code. 您的代码顶部有一个重复的包声明。 I would remove the second one ( org.openqa.selenium.example ) since your code is probably in the SeleTest1 folder. 由于您的代码可能位于SeleTest1文件夹中, SeleTest1我将删除第二个( org.openqa.selenium.example )。

Your package declaration is not required to match the one of the framework you are using. 不需要您的程序包声明与所使用的框架之一匹配。

When you export the selenmium IDE recorded test case into webdriver format, by default the package statement will get added as 当您将selenmium IDE记录的测试用例导出为webdriver格式时,默认情况下,package语句将添加为

package org.openqa.selenium.example;

We need to modify it as per our package name created in Eclipse. 我们需要根据在Eclipse中创建的包名称对其进行修改。

So, in your case, you can remove the below duplicate line. 因此,根据您的情况,您可以删除以下重复的行。

package org.openqa.selenium.example;

You will not get the 2nd error also once you have done this modification. 完成此修改后,您也不会收到第二个错误。

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

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