2016-10-01 73 views
0

我的代码如下:硒与Firefox不能访问页面

public static void main(String[] args) { 
    WebDriver driver; 
    System.setProperty("webdriver.gecko.driver", "E:\\gecko\\geckodriver.exe"); 
    System.out.println("Gecko Driver Found"); 
    driver =new FirefoxDriver(); 
    System.out.println("WebDriver Established"); 
    driver.get("http://www.supremenewyork.com/shop/all/sweatshirts"); 
    System.out.println("Connection Established"); 
} 
} 

运行这给了我SessionNotCreatedException当程序试图建立司机,我将在底部倾倒。我只是想让程序现在加载一个网页,所以任何帮助都会很棒。

控制台输出:

Sep 30, 2016 10:26:37 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end 1475288797965 addons.xpi WARN Error loading bootstrap.js for {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: Module resource://gre/modules/commonjs/sdk/addon/bootstrap.js is not found at resource://gre/modules/commonjs/sdk/addon/bootstrap.js (resource://gre/modules/commonjs/toolkit/require.js:24) JS Stack trace: make/[email protected]:24:12 < @bootstrap.js:10:23 < @XPIProvider.jsm:4339:1 < [email protected]:4339:7 < [email protected]:4414:1 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 1475288797965 addons.xpi WARN Exception running bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: TypeError: this.bootstrapScopes[aAddon.id][aMethod] is not a function (resource://gre/modules/addons/XPIProvider.jsm:4442:8) JS Stack trace: [email protected]:4442:9 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 Sep 30, 2016 10:26:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Falling back to straight W3C remote end connection 1475288799084 addons.xpi WARN Error loading bootstrap.js for {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: Module resource://gre/modules/commonjs/sdk/addon/bootstrap.js is not found at resource://gre/modules/commonjs/sdk/addon/bootstrap.js (resource://gre/modules/commonjs/toolkit/require.js:24) JS Stack trace: make/[email protected]:24:12 < @bootstrap.js:10:23 < @XPIProvider.jsm:4339:1 < [email protected]:4339:7 < [email protected]:4414:1 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 1475288799085 addons.xpi WARN Exception running bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: TypeError: this.bootstrapScopes[aAddon.id][aMethod] is not a function (resource://gre/modules/addons/XPIProvider.jsm:4442:8) JS Stack trace: [email protected]:4442:9 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 Sep 30, 2016 10:26:40 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Falling back to original OSS JSON Wire Protocol. 1475288800182 addons.xpi WARN Error loading bootstrap.js for {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: Module resource://gre/modules/commonjs/sdk/addon/bootstrap.js is not found at resource://gre/modules/commonjs/sdk/addon/bootstrap.js (resource://gre/modules/commonjs/toolkit/require.js:24) JS Stack trace: make/[email protected]:24:12 < @bootstrap.js:10:23 < @XPIProvider.jsm:4339:1 < [email protected]:4339:7 < [email protected]:4414:1 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 1475288800183 addons.xpi WARN Exception running bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}: TypeError: this.bootstrapScopes[aAddon.id][aMethod] is not a function (resource://gre/modules/addons/XPIProvider.jsm:4442:8) JS Stack trace: [email protected]:4442:9 < [email protected]:3334:1 < [email protected]:3443:23 < [email protected]:3604:34 < [email protected]:2092:25 < [email protected]:208:12 < [email protected]:667:5 < [email protected]:824:9 < [email protected]:2402:5 < [email protected]:55:7 Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=ANY}], required capabilities = Capabilities [{}] Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:29:23 -0700' System info: host: [REDACTED], ip: [REDACTED], os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101' Driver info: driver.version: FirefoxDriver at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:80) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:247) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:235) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:230) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:226) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:124) at copDatBogo.SupremeAccesser.main(SupremeAccesser.java:11)

回答

0

多亏了郑文聪做了编辑,我能够gopogle异常并诊断问题。

我重新安装了firefox,但是这样做了一个新的目录。我最后的功能代码如下:

package copDatBogo; 
import java.io.File; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxBinary; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
public class SupremeAccesser { 



public static void main(String[] args) { 
     WebDriver driver; 
     System.setProperty("webdriver.gecko.driver", "E:\\gecko\\geckodriver.exe"); 
     File pathToBinary = new File("path to firefox.exe"); 
     FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); 
     FirefoxProfile ffProfile = new FirefoxProfile(); 
     System.out.println("Gecko Driver Found"); 
     driver =new FirefoxDriver(ffBinary, ffProfile); 
     System.out.println("WebDriver Established"); 
     driver.get("URL"); 
     System.out.println("Connection Established"); 
    } 
} 

我为我平淡的诊断技能道歉,并会在未来更彻底梳理的错误消息。