Java org.openqa.selenium.SessionNotCreatedException:无法设置首选项:无法读取配置文件首选项文件

时间:2018-04-09 17:51:07

标签: java selenium webdriver

我可以在Eclipse中运行这个程序,但是当我将它导出到runnable jar文件

时却无法运行
public void downloadProcess() throws Exception{
    File dir = new File(getDir(), getStockId()+"-"+getFromYear()+"Q"+getFromQuarter()+"~"+getToYear()+"Q"+getToQuarter());
    dir.mkdirs();
    String path = new File(".").getCanonicalPath().toString();
    System.setProperty("webdriver.gecko.driver", path+"\\geckodriver.exe");
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.dir", dir.toString());
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
    firefoxProfile.setPreference("pdfjs.enabledCache.state", false);

    FirefoxOptions options = new FirefoxOptions();
    options.setProfile(firefoxProfile);
    System.out.println(options);
    WebDriver driver = new FirefoxDriver(options);//line:87

在Eclipse中,它可以工作,但是在一个可运行的jar中,我得到了这个

  

org.openqa.selenium.SessionNotCreatedException:无法设置偏好:无法读取简档偏好文件生成信息:版本:' 3.11.0&#39 ;,修改:' e59cfb3&#39 ;,时间:' 2018-03-11T20:33:08.638Z'   系统信息:主持人:' LITINSU',ip:' 192.168.1.112',os.name:' Windows 10',os.arch:' amd64',os.version:' 10.0',java.version:' 10'   驱动程序信息:driver.version:FirefoxDriver   远程堆栈跟踪:       at java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)       at java.base / jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)       at java.base / java.lang.reflect.Constructor.newInstance(Unknown Source)       在org.openqa.selenium.remote.W3CHandshakeResponse.lambda $ new $ 0(W3CHandshakeResponse.java:57)       在org.openqa.selenium.remote.W3CHandshakeResponse.lambda $ getResponseFunction $ 2(W3CHandshakeResponse.java:104)       在org.openqa.selenium.remote.ProtocolHandshake.lambda $ createSession $ 0(ProtocolHandshake.java:123)       at java.base / java.util.stream.ReferencePipeline $ 3 $ 1.accept(Unknown Source)       at java.base / java.util.Spliterators $ ArraySpliterator.tryAdvance(Unknown Source)       at java.base / java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)       at java.base / java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)       at java.base / java.util.stream.AbstractPipeline.copyInto(Unknown Source)       at java.base / java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)       at java.base / java.util.stream.FindOps $ FindOp.evaluateSequential(Unknown Source)       at java.base / java.util.stream.AbstractPipeline.evaluate(Unknown Source)       at java.base / java.util.stream.ReferencePipeline.findFirst(Unknown Source)       在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)       在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)       在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)       在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)       在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)       在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)       在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:132)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:120)       在downloadPDF.DownloadPDF.downloadProcess(DownloadPDF.java:87)       在main.Main.lambda $ 0(Main.java:178)       在javafx.base / com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(未知来源)       在

0 个答案:

没有答案