简体   繁体   中英

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)

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; 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

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?

where Can I find out the location of the package-org.openqa.selenium.example?

Here is my code copied from Google code get started with Selenium my project structure 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)

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.

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

package org.openqa.selenium.example;

We need to modify it as per our package name created in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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