我试图用这个示例代码来自动化[electron-api-demos][1]应用程序。
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。
我在localhost得到以下内容,但不是元素。
可检查的WebContents scanneruiappfilesindex.html。
有谁能帮我理解我哪里出错了.把selenium改成alpha后,我能够运行这个,而且没有错误。
更新编辑。
我能够导航到谷歌和自动在CEF。但我不能控制或执行任何行动的应用程序的菜单栏或按钮或文本框。
我的cef是基于chrome 57.所以我降级了chrome浏览器到57,chrome驱动程序到2.26和selenium Java库到2.36。
但我仍然无法点击桌面应用程序的特定按钮或文本框。但能够driver.navigate到谷歌和执行测试。
有谁能在这里帮助?我使用的是Java,Selenium
我也试过在电子上的应用,如上所述,仍然没有成功。
@DebanjanB,谢谢你的帮助,在我把selenium的版本改为alpha后,我就可以连接到应用程序而不出错了,我现在使用的是下面的代码。
public static void main(String args[]) throws IOException, InterruptedException {
int port = 9223;
// Open App
Runtime.getRuntime().exec(
"C:\\Program Files\\SampleApp.exe", null,
new File("C:\\Program Files\\SampleApp"));
ChromeOptions options = new ChromeOptions();
String remoteDebuggingAddress = "localhost:" + port;
options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
options.addArguments("remote-debugging-port=9223");
options.setBinary(
"C:\\Program Files\\SampleApp.exe");
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\xyz\\eclipse-workspace\\xyz\\src\\demo1\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
System.out.println(driver.getTitle());
}
问题是,我无法访问chromium中的元素。http:/localhost:9223当我在本地主机上打开chromium或chrome浏览器时,会显示以下文字。通常情况下,链接是应该的。链接或WebElements不显示。
可检查的网页内容 scanneruiappfilesindex.html。
再次检查你的代码,弹出缺失库的错误,检查目录中是否有资源缺失。
检查你的Java注释,如果它们在你的代码中缺失,请关注这一行。
无法启动新的会话。可能的原因是远程服务器地址无效或浏览器启动失败。Build info: version: '4.0.0-alpha-3', revision: '8c567de6dc' System info: host: 'INDMRZBK5X95V6G', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_241' 驱动程序信息: driver.version: RemoteWebDriver at