【发布时间】:2020-10-03 22:06:21
【问题描述】:
我正在尝试使用此示例代码自动化 [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:
我在 localhost 得到以下内容,但不是元素:
可检查的 WebContents 扫描仪ui/appfiles/index.html
谁能帮我理解我哪里出错了。 将 selenium 更改为 alpha 后,我可以毫无错误地运行它。
更新编辑:
我能够导航到 google 并在 cef 中实现自动化。但我无法控制或对应用程序的菜单栏或按钮或文本框执行任何操作。
我的 cef 基于 chrome 57 。所以我将 chrome 浏览器降级为 57 ,将 chrome 驱动程序降级为 2.26 ,将 selenium Java 库降级为 2.36 。
我仍然无法单击桌面应用程序特定的按钮或文本框。但我能够驱动程序。导航到谷歌并执行测试。
有人可以帮忙吗?我正在使用 Java ,硒
我也试过上面提到的电子申请,还是没有运气
【问题讨论】:
-
明天第一个小时我会重新审视你的问题。但是我可以看到您正在使用 Selenium v 4.0.0-alpha-3 这是一个 Alpha 版本。我们仍在开发 Beta 版本,最后一个稳定版本是 Selenium v 3.141.159,最后一个稳定主要版本是 Selenium v 3.14.0
-
好的,我会检查稳定版本并更新
-
根据错误堆栈跟踪,所有 3 个代码块都存在明显问题。您能否请edit the question 将其限制为具有足够详细信息的特定问题以找出适当的答案。
-
我将问题内容编辑为一个问题
-
粗略会导致二进制版本不匹配问题。
标签: java selenium-webdriver electron desktop-application