java - 有没有办法使用 Selenium 或其他一些 java API 以编程方式创建新的命名 Firefox 配置文件?
问题描述
我正在寻找一种以编程方式创建新配置文件的方法,但找不到任何特定的 API 或任何简单的解决方案,例如在特定文件夹中创建特定文件等。有人遇到过这个问题吗?
解决方案
像这样的东西:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class NewFirefoxProfilesCreator {
public static void main(String[] args) {
int end =100;
int start = 1;
for (int i=start; i<=end; i++) {
try {
Process process = Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -no-remote -CreateProfile rnn"+i);
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
int exitVal = process.waitFor();
if (exitVal == 0) {
System.out.println("Success!");
System.out.println(output);
} else {
//abnormal...
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
循环创建 100 个 Firefox 配置文件。
推荐阅读
- javascript - 猫头鹰旋转木马滑块定制
- javascript - selectize.js 重置所选值
- reactjs - 在 React 应用程序上查询 API 并重定向到搜索栏(组件)的结果页面
- testng - Testng 测试执行未按字母顺序发生
- yii2 - 无需登录即可访问控制器/视图 YII2 Advance
- ios - 由于依赖冲突,Parse/FacebookUtils 和 FacebookCore 无法正常工作。
- travis-ci - 如何在 Travis CI 上捕获工件上传功能?
- java - 将 Multimap ArrayList 作为字符串返回
- sql - 查询事务
- c - 在C编程中根据一列对二维数组进行排序