2015-10-05 108 views
1

我的代碼是網址無法打開與webdriver的

package mentor.qa.selenium; 

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

public class WDDemo1 { 

    public static void main(String[] args){ 
     WebDriver driver = new FirefoxDriver();   
     driver.get("http://www.google.com"); 
    } 
} 

我使用的是最新的Java jar文件2.47.1和Firefox 41.0.1。它啓動Firefox,但不會去鏈接。我該如何解決這個問題?

+0

你有任何額外的錯誤消息,堆棧跟蹤或日誌? – Sebastian

+0

問題中有5個警告。構建路徑指定執行環境javaSE-1.7。工作區中沒有安裝與此環境嚴格兼容的JRE。 –

+0

[Selenium WebDriver.get(url)可能的重複不會打開URL](http://stackoverflow.com/questions/7347494/selenium-webdriver-geturl-does-not-open-the-url) – Lucky

回答

0

代碼正在工作,但優化了進口。

我用極小的編輯來運行你的代碼。它打開谷歌網站。重新驗證是否已經在構建路徑中導入了selenium-java和selenium-server-standalone jar文件。

package com.jayant.selenium; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class SampleSelenium { 
    public static void main(String[] args){ 
     WebDriver driver = new FirefoxDriver(); 
     driver.get("http://www.google.com"); 
    } 
} 
-1

你的代碼是完美的。這可能是配置問題,即使用相同代碼的較低版本的Firefox。它會工作

+0

你有沒有在較低的版本嘗試它,或者它只是一個猜測? –

+0

我在Mozilla Firefox 38.0中使用了相同的代碼,它工作正常 –

+0

這是一個日食問題,正如我在我的回答中提到的 –