![](/img/trans.png)
[英]The declared package “java.lang” doesn't match the expected package “”
[英]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.