Unable to connect to the electron / CEF app using selenium web driver

独自空忆成欢 提交于 2020-06-21 05:41:46

问题


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

             }

    }

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/

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

Inspectable WebContents scannerui/appfiles/index.html

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 .

Updated edit :

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.

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.

Can anyone help here? I am using Java , selenium

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


回答1:


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

    }

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.

Inspectable WebContents scannerui/appfiles/index.html




回答2:


check your code again, its pop up error of missing library. check if any resource if missing on directory,

check your Java annotation if they are missing in your code and Focus on this line

Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 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 info: driver.version: RemoteWebDriver at



来源:https://stackoverflow.com/questions/62372230/unable-to-connect-to-the-electron-cef-app-using-selenium-web-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!