如何将ChromeDriver加入JAR? [英] How can I include ChromeDriver in a JAR?

查看:416
本文介绍了如何将ChromeDriver加入JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个网络自动化程序,到目前为止,它使用Selenium的FirefoxDriver工作正常。但是,如果未安装Firefox,我想使其使用Chrome。我下载了ChromeDriver,将其放在Eclipse项目的一个文件夹中,并运行它。当我添加了 System.setProperty(webdriver.chrome.driver,Drivers / chromedriver.exe); 它工作正常。但是,当我尝试导出它(使用Eclipse的标准导出)。它崩溃,我相信,因为它找不到ChromeDriver(我认为这是因为导出它与FirefoxDriver工作正常)。



我尝试将.JAR更改为.ZIP以查看内部,我看到驱动程序文件夹被剥离,只需在顶级JAR中放入 chromedriver.exe 。我尝试将属性更改为 System.setProperty(webdriver.chrome.driver,chromedriver.exe); 但仍然崩溃。



有谁知道为什么导出的JAR无法找到 chromeDriver ,尽管事实上我已经证实它在JAR中?



谢谢,
丹尼尔

解决方案

这是在罐子里,但不能被执行(与从zip文件中运行.exe相同),您必须在运行它之前解压缩它。


I'm writing a web-automation program and so far, it works fine using Selenium's FirefoxDriver. However, I want to make it use Chrome if Firefox is not installed. I downloaded the ChromeDriver, put it inside a folder in my Eclipse project, and ran it. After I added System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe"); it worked fine. However, when I try to export it (using Eclipse's standard Export). It crashes, I believe because it can't find the ChromeDriver (I think this because exporting it with FirefoxDriver works fine).

I have tried changing the .JAR to a .ZIP in order to look inside, and I see that the driver folder was stripped away, simply putting chromedriver.exe inside the top-level JAR. I tried changing the property to System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); but still crashes.

Does anyone know why the exported JAR is unable to find chromeDriver, despite the fact that I have verified that it is in the JAR?

Thanks, Daniel

解决方案

It's in the Jar but cannot be executed (same as trying to run an .exe from a zip file), you have to extract it before running it

这篇关于如何将ChromeDriver加入JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆