2017-05-01 22 views
-2

私はSeleniumを使い始めようとしています。私はSelenium Stand Alone Server、Selenium for JAVA、GeckoDriverをダウンロードしました。スタンドアローンサーバーとSelenium for JAVAのすべての.jarファイルをEclipseのビルドパスに追加しました。私は私のプログラムを実行すると、私はfollwingエラーを取得する:Seleniumをどのように使い始めることができますか?

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    FirefoxOptions cannot be resolved to a type 
    FirefoxOptions cannot be resolved to a type 

    at check.Selenium_Basic.main(Selenium_Basic.java:14) 

私のコードは以下の通りです:これが動作しない理由を

package check; 
import org.openqa.selenium.*; 

import org.openqa.selenium.firefox.FirefoxDriver; 

import org.openqa.selenium.support.ui.Select; 


public class Selenium_Basic { 

    public static void main(String[] args) {   
     System.setProperty("webdriver.gecko.driver", "C:\\Users\\User1\\Documents\\geckodriver-v0.16.1-win32\\geckodriver.exe"); 

     FirefoxOptions options = new FirefoxOptions(); 
     options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine 

     FirefoxDriver driver = new FirefoxDriver(options); 
     driver.get("http://www.google.com"); 
    } 
} 

は、あなたたちは知っていますか?私はこれを使用し始めることができるステップガイドで良いステップがありますか?私は多くのガイドを見てきましたが、私が間違って行ったことを理解することはできません。

+0

することで、必要なファイルやビルド・パスが欠落しているようです間違っています。 – csmckelvey

+0

そのクラスのインポートはどうですか? – Tom

答えて

1

コードはよく見えます。 FirefoxOptionsのインポートステートメントがありません。他のインポートステートメント&でコードに以下の行を追加することができます。

import org.openqa.selenium.firefox.FirefoxOptions; 

また、Selenium StandAlone Serverを使用する必要はありません。 GeckoDriverを使ってJavaだけで動作するセレンは正常に動作します。あなたはまた、完全なセットアップに関連する手順については、このリンクをチェックすることができるのGecko 16

との互換性として、セレン3.4を使用していることを確認してください -

Selenium 3.4 – Complete Guide to the latest Selenium WebDriver