【问题标题】:Unable to connect to the electron / CEF app using selenium web driver无法使用 selenium 网络驱动程序连接到电子 / CEF 应用程序
【发布时间】: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:

http://localhost:9223/

我在 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


【解决方案1】:

@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/ 访问铬元素 当我在本地主机上打开 chromium 或 chrome 浏览器时,会显示以下文本。 通常需要一个链接。链接或 WebElement 不显示。

可检查的 WebContents 扫描仪ui/appfiles/index.html

【讨论】:

    【解决方案2】:

    再次检查您的代码,它会弹出缺少库的错误。检查目录中是否缺少任何资源,

    如果您的代码中缺少 Java 注释,请检查它们并关注这一行

    无法开始新会话。可能的原因是远程服务器地址无效或浏览器启动失败。构建信息:版本:'4.0.0-alpha-3',修订:'8c567de6dc' 系统信息:主机:'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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-27
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2011-07-11
      • 1970-01-01
      相关资源
      最近更新 更多