我正在尝试使用此示例代码自动化 [electron-api-demos][1]app。
public static void main(String args[]) throws IOException, InterruptedException {
int port = 9223;// Open App
Runtime.getRuntime().exec(
"C:\\Program Files\\Sample.exe"
, null, new
File("C:\\Program Files\\Sample"
));
ChromeOptions options = new ChromeOptions();
String remoteDebuggingAddress = "localhost:" + port;
options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
options.addArguments("remote-debugging-port=9223");
// options.addArguments("electron-port="+port);
options.setBinary(
"C:\\Program Files\\Sample.exe");
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\narays24\\eclipse-workspace\\xyz\\src\\demo1\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
System.out.println(driver.getTitle());
String location = "C:\\Users\\narays24\\eclipse-workspace\\xyz\\src\\demo1";
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
String time = dateFormat.format(now);
File dir = new File(location + time);
if (!dir.exists())
{
dir.mkdir();
}
else
{
//System.out.println("directory already exists");
//Do nothing
}
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(location + time + "\\screen1.png"));
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
我能够访问该应用程序并获取屏幕截图。
我无法通过以下端口访问 cef:
http://本地主机:9223/ http://localhost:9223/
我在 localhost 收到以下内容,但没有收到元素:
可检查的 WebContents Scannerui/appfiles/index.html
谁能帮我理解我哪里出了问题。
将 selenium 更改为 alpha 后,我可以毫无错误地运行它。
更新编辑:
我能够导航到 google 并在 cef 中实现自动化。但我无法在应用程序的菜单栏、按钮或文本框上控制或执行任何操作。
我的cef基于chrome 57。所以我将chrome浏览器降级到57,chrome驱动程序降级到2.26,selenium Java库降级到2.36。
我仍然无法单击桌面应用程序特定的按钮或文本框。但我能够 driver.navigate 到谷歌并执行测试。
有人可以帮忙吗?我正在使用Java,硒
我也尝试过如上所述的电子应用程序,但仍然没有运气