2017-10-21 115 views
0

我無法用硒推出Firefox瀏覽器推出Firefox瀏覽器的webdriver 3.4.0無法使用硒網絡驅動程序

瀏覽器版本:火狐54.0.1

這是我的代碼:

public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe"); 
    System.setProperty("webdriver.gecko.driver", "C:\\xx\\geckodriver.exe"); 
    WebDriver driver=new FirefoxDriver(); 
    driver.get("http://www.google.co.in"); 
    driver.quit(); 
} 
} 

得到錯誤

1508548441651 geckodriver信息geckodriver.18.0 210 1508548441660 geckodriver INFO正在監聽127.0.0.1:48046異常 在線程「main」中org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException:連接到 localhost:48046 [localhost/127.0.0.1,本地主機/ 0:0:0:0:0:0:0:1] 失敗:連接被拒絕:連接構建信息:版本:'3.4.0', 修訂:'未知',時間:'未知'系統信息:host: 'ADMINRG-627BJ6K',ip:'192.168.1.3',os.name:'Windows 10',os.arch: 'amd64',os.version:'10 .0',java.version:'1.8 .0_131'驅動程序信息: driver.version:FirefoxDriver at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) 在 org.openqa.selenium.remote。 RemoteWebDriver.startSession(RemoteWebDriver.java:236) 在 org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:137) 在 org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:191) 在 org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:108) 在 org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:104) 在com.webdriver.Testing.main( Testing.java:15)原因: org.apache.http.conn.HttpHostConnectException:連接到 localhost:48046 [localhost/127.0.0.1,localhost/0:0:0:0:0:0:0:1] 失敗:連接被拒絕:在 org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) 在 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) 在 連接org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) 在 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) 在 org.apache。 http.impl.execchain.P rotocolExec.execute(ProtocolExec.java:185) 在 org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) 在 org.apache.http.impl.execchain.RedirectExec.execute( RedirectExec.java:111) 在 org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) 在 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java: 72) 在 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) 在 org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient。的java:139) 在 org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87) 在 org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:343) 在 org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159) 在 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142) 在 org.openqa.selenium.remote .service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) ... 8更多原因:java.net.ConnectException:連接被拒絕: 連接在java.net.DualStackPlainSocketImpl.waitForConnect(原生 方法)在java.net.DualStackPlainSocketImpl.socketConnect(未知 源)在java.net.AbstractPlainSocketImpl.doConnect(未知來源) 在java.net.AbstractPlainSocketImpl.connectToAddress(未知來源) 在java.net.AbstractPlainSocketImpl.connect (Unknown Source)at java.net.PlainSocketImpl.connect(Unknown Source)at java.net.SocksSocketImpl.connect(Unknown Source)at java.net.Socket.connect(Unknown Source)at org.apache.http .conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ... 23更多

+0

你爲什麼要加入這個說法同樣的方式:'System.setProperty(「webdriver.firefox.bin」 「C:\\ Program Files \\ Mozilla Firefox \\ firefox.exe」)'? – DG4

+0

我得到了其他朋友的建議。所以我補充說。 – Biswajit440

+0

任何建議。因爲我仍然面臨這個問題。 – Biswajit440

回答

0

試試這個方法:我正在使用C#,但是這種方式對我很有用。您可以按照用Java做 提供「firefox.exe」 &「GeckoDriver」作爲您的本地路徑

var binary = new FirefoxBinary(@"----Firefox.exe Path------"); 
var profile = new FirefoxProfile(); 
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"----GeckoDriver Path------"); 
service.FirefoxBinaryPath = @"----Firefox.exe Path------"; 
driverInstance = new FirefoxDriver(service);