java - 无法使用 selenium 网络驱动程序连接到 Electron /CEF 应用程序

标签 java selenium-webdriver electron desktop-application

我正在尝试使用此示例代码自动化 [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://localhost:9223/



我在 localhost 得到以下内容,但不是元素:

Inspectable WebContents scannerui/appfiles/index.html



谁能帮我理解我哪里出错了。
将 selenium 更改为 alpha 后,我可以毫无错误地运行它。

更新编辑:

我能够导航到 google 并在 cef 中自动化。但我无法控制或对应用程序的菜单栏或按钮或文本框执行任何操作。

我的 cef 基于 chrome 57 。所以我将 chrome 浏览器降级为 57 ,将 chrome 驱动程序降级为 2.26 ,将 selenium Java 库降级为 2.36 。

我仍然无法单击桌面应用程序特定的按钮或文本框。但我能够驱动程序。导航到谷歌并执行测试。

有人可以在这里帮忙吗?我正在使用 Java , Selenium

我也试过上面提到的 Electron 应用程序,仍然没有运气

最佳答案

@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());

    }

问题是我无法在 http://localhost:9223/ 访问 Chrome 中的元素
当我在本地主机上打开 chromium 或 chrome 浏览器时,会显示以下文本。
通常需要一个链接。不显示链接或 WebElement。

Inspectable WebContents scannerui/appfiles/index.html

关于java - 无法使用 selenium 网络驱动程序连接到 Electron /CEF 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62403617/

相关文章:

java - 身份验证失败异常 - 在批量邮件发送代码中

c# - 程序代码主体中元素的首选顺序是什么?为什么?

android - Appium:Android 资源 ID:在他们的 selenium 集成中转化为什么?

java - innerhtml 中的对象未被 selenium webdriver 识别

electron - 在主流程中,如何判断消息是来自send还是sendSync?

javascript - Electron :自定义协议(protocol)示例在 Windows 中不起作用

java - 网络服务 : Request-Response Mapper

java - 如何使用 rally rest api 查找给定迭代和给定项目下的用户故事列表

python - 如何将FirefoxWebElememt转换为字符串类型?

.net - Electron-Edge-Js和.net标准2.0兼容性问题