使用命令行参数

时间:2016-05-09 06:26:49

标签: java selenium selenium-webdriver selenium-chromedriver electron

我有一个Electron应用程序(chat.exe)并使用以下代码片段我可以使用 Chromedriver 启动它:

ChromeOptions options = new ChromeOptions();
options.setBinary(System.getenv("CHAT")); // CHAT = path to Chat.exe
driver = new ChromeDriver(options);

我的问题是:如何使用命令行参数启动它?

e.g。 chat.exe -- --electronPort 5000 --webpackPort 3000 --accessToken 123456789

我尝试了以下方式,但没有奏效:

ChromeOptions options = new ChromeOptions();
options.setBinary(System.getenv("CHAT")); // CHAT = path to Chat.exe
options.addArguments("-- --electronPort 5000 --webpackPort 3000 --accessToken 123456789");
driver = new ChromeDriver(options);

显示以下错误:

org.openqa.selenium.WebDriverException: chrome not reachable

2 个答案:

答案 0 :(得分:1)

以下格式有效(如@ user861594指定):

options.addArguments("<Key>=<value>");

然而,问题是chromedriver不能采用camelCase格式的参数。在开发人员将cll args的语法从camelCase修改为连字符后,上述解决方案起作用。

e.g。

options.addArguments("electron-port=5000");
options.addArguments("webpack-port=3000");
options.addArguments("access-token=12345‌​6789");

答案 1 :(得分:0)

ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");

在非标准位置设置Chrome可执行文件,而不是设置除chrome之外的任何其他可执行文件。因为您提供的不是chrome二进制文件(在您的情况下是CHAT.exe)驱动程序打开CHAT而不是chrome浏览器并且抱怨chrome无法访问。

Webdriver仅用于自动化Web应用程序,而不用于独立应用程序自动化。为此,您可以使用其他工具,如“AutoIt”。

相关问题