无法使用 selenium 网络驱动程序连接到电子/CEF 应用程序

Unable to connect to the electron / CEF app using selenium web driver(无法使用 selenium 网络驱动程序连接到电子/CEF 应用程序)
本文介绍了无法使用 selenium 网络驱动程序连接到电子/CEF 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用此示例代码自动化 [electron-api-demos][1]app.

I am trying to automate [electron-api-demos][1]app using this sample code.

  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:

I am able to access the app and get a screenshot. I am not able to access the cef through the below port :

http://localhost:9223/

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

I am getting the following at the localhost , but not the elements :

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

Inspectable WebContents scannerui/appfiles/index.html

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

Can anyone help me understand where I am going wrong. After changing the selenium to alpha , I am able to run this with out errors .

更新

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

I am able to navigate to google and automate in cef . But I am not able to control or perform any actions on application's menu bar or buttons or text boxes.

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

My cef is based on chrome 57 .so I downgraded the chrome browser to 57 , chrome driver to 2.26 and selenium Java libraries to 2.36 .

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

Still I am not able to click on desktop application specific buttons or text boxes. But am able to driver.navigate to google and perform tests.

有人可以帮忙吗?我正在使用 Java ,硒

Can anyone help here? I am using Java , selenium

我也试过上面提到的电子申请,还是没有运气

I also tried on electron application as mentioned above, still no luck

推荐答案

@DebanjanB,谢谢您的帮助.将 selenium 的版本更改为 alpha 后,我可以无错误地连接到应用程序.我现在正在使用以下代码:

@DebanjanB, Thanks for the help. After I changed the version of the selenium to alpha , I am able to connect to the app with out errors. I am using the following code now :

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

The issue is I am not able to access the elements in chromium at http://localhost:9223/ When I open the chromium or chrome browser at teh local host the following text is displayed . Normally a link is expected . Link or the WebElements are not displayed.

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

Inspectable WebContents scannerui/appfiles/index.html

这篇关于无法使用 selenium 网络驱动程序连接到电子/CEF 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)