[英]Error while executing Selenium script in Eclipse IDE
我收到以下腳本的以下錯誤。 我已將所有jar文件添加到庫中。
============================================================
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
at webdriver/Demo.Sample.main(Sample.java:11)
=============================================================
package Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hello");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
好像您導入了錯誤的jar文件。 從https://selenium-release.storage.googleapis.com/index.html?path=2.53/下載selenium-server-standalone-2.53.1.jar
文件,並將其導入eclipse中並刪除其他jar文件。
由於您嘗試使用Selenium WebDriver自動化Firefox,因此還需要下載Firefox可執行二進制文件。 根據您的瀏覽器版本,您可以從https://github.com/mozilla/geckodriver/獲取gecko
驅動程序
在驅動程序初始化之前,在代碼中添加以下行,並提供具有名稱和范圍的Firefox可執行二進制文件的絕對路徑:
System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable");
下面是修改后的代碼:
package Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable\\geckodriver.exe"); // Provide your system path to the gecko driver with name and extension here
System.out.println("hello");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
希望對您有幫助...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.