私は Selenium を初めて使用し、http://docs.seleniumhq.org/docs/03_webdriver.jspの例を使用しようとしています。しかし、うまくいきません。Mavenを介したJUnitテストから、またはJavaアプリケーションとしてのEclipse Junoから実行するたびに、次のような結果が得られます。
Exception in thread "main" org.openqa.selenium.WebDriverException: Session not found: 1d1a9aa2-f089-4f36-bb05-e1505c7b4e85
Command duration or timeout: 28 milliseconds
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0'
Session ID: 1d1a9aa2-f089-4f36-bb05-e1505c7b4e85
Capabilities [{handlesAlerts=true, rotatable=false, databaseEnabled=true, locationContextEnabled=true, acceptSslCerts=true, applicationCacheEnabled=true, cssSelectorsEnabled=true, nativeEvents=true, takesScreenshot=true, platform=XP, browserName=firefox, javascriptEnabled=true, version=17.0.6, webStorageEnabled=true, browserConnectionEnabled=true}]
Driver info: org.openqa.selenium.firefox.FirefoxDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
失敗しているコードは次のとおりです。
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com"); // FAILURE
私はそれをデバッグし、FirefoxDriver コンストラクターが呼び出されると、Firefox ウィンドウが実際に私のシステムで開き、その後消えてから再び開くことを確認しました。次に、driver.get() 呼び出しで失敗します。
このサイトを検索したところ、問題への参照が見つかりました。問題は Chrome または IE にありましたが、Firefox は機能しました。他のすべては別のエラーのようでした。開いたままのウィンドウから Firefox のバージョンを取得しようとしましたが、[Firefox について] を選択したときに表示されるのは次のとおりです。
<window xmlns:html="http://www.w3.org/1999/xhtml"
^
Firefox を直接起動すると、Firefox のバージョンが 17.0.6 で、「現在、esr 更新チャネルを使用しています」と表示されます。ちなみに、そのウィンドウを開いたままにしても効果はありません。新しい Firefox ウィンドウが開き、閉じ、再度開いて、そのままにしておきます。