无法使用selenium webdriver打开新的URL

时间:2014-02-24 15:30:33

标签: selenium

当使用selenium使用FirefoxDriver的.get()方法尝试打开新网址时,新网址没有被打开,而是我得到一个空白屏幕,但有以下异常。

我的Firefox版本是27 Selenium罐子版“selenium-2.39.0” 在ChromeDriver和IRDriver的情况下,我得到了同样的例外

Exception in thread "main" org.openqa.selenium.WebDriverException: f.QueryInterface is  not a function
Command duration or timeout: 50 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'ANKUR-PC', ip: '169.254.81.96', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_40'
Session ID: 3e90ea0a-fce7-44c4-9df0-15231046ae45
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=27.0.1}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:276)
    at Selenium.main(Selenium.java:14)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: f.QueryInterface is not a function
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'ANKUR-PC', ip: '169.254.81.96', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_40'
Driver info: driver.version: unknown
    at <anonymous class>.FirefoxDriver.prototype.get(file:///C:/Users/ANKUR/AppData/Local/Temp/anonymous1797840660297297360webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8720)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/ANKUR/AppData/Local/Temp/anonymous1797840660297297360webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10831)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/ANKUR/AppData/Local/Temp/anonymous1797840660297297360webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10836)
    at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/ANKUR/AppData/Local/Temp/anonymous1797840660297297360webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10778)

我使用的代码是:

    Proxy prox = new Proxy();
    prox.setAutodetect(true);

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability("browser", "firefox");
    cap.setCapability(CapabilityType.PROXY,prox);
    FirefoxDriver f= new FirefoxDriver(cap);

    f.get("www.google.com");

4 个答案:

答案 0 :(得分:3)

请在网址前使用http前缀。将该行重写为f.get("http://www.google.com");。这应该有用。

答案 1 :(得分:0)

方法获取需要将协议作为网址的一部分。

变化:

String baseurl = "www.google.com";

要:

String baseurl = "http://www.google.com";

答案 2 :(得分:0)

试试这个:

 FirefoxProfile ff = new FirefoxProfile();
 FirefoxBinary binary = new FirefoxBinary(new File("C:\\Program Files (x86)\\Mozilla       Firefox\\firefox.exe"));
 WebDriver driver = new FirefoxDriver(binary,ff);
 driver.get(URL);

答案 3 :(得分:-2)

请卸载你最新版本的firefox并使用像firefox 22 becoz这样的版本我也面临同样的问题