Failing to access the web elements in NW.js exe app using Selenium JavaScript

129 views
Skip to first unread message

Mukesh

unread,
Nov 7, 2023, 6:23:57 AM11/7/23
to nw.js

Hello NW.js fam,


I’m trying to automate NW.js exe file using selenium JavaScript and have been stuck on this issue for a long time. I find it hard to establish the connection between selenium Webdriver and NW.js exe app. I have heard it’s possible to test NW.js app with Selenium and Chromedriver. The test scripts are in Python but I’m writing tests in JavaScript.


I will link the JavaScript file for the reference

I have the Chromedriver in the project folder PATH and executing the following script.


Code:


require('chromedriver');


const {Builder, By, Key} = require('selenium-webdriver');

const chrome = require('selenium-webdriver/chrome');


let options = new chrome.Options();

options.setChromeBinaryPath('dist/src/nw.exe'); // mentioning the PATH to NW.exe


async function openNwExe(){

    let driver = new Builder()

    .forBrowser('chrome')  

    .setChromeOptions(options)

    .build();   


    await driver.get('src/views/index.html'); //to open the front page of the app    

    

    try{

        //trying find the input box element and sending the key values

        await driver.findElement(By.id("input")).sendKeys("San Francisco");              

    }    

    finally{

        // Close the WebDriver session and exit the NW.js application

        await driver.sleep(1000);

        await driver.quit();

      }

}

openNwExe(); //function call


If I run the script,

The Selenium Webdriver automatically detects Chromedriver PATH in project folder and opens the NW.exe app.

1.The Issue is I find it hard to establish connection between nw.exe and access the elements.


2. After sometimes the nw.exe crashes or if I manually close it the following error is coming.


Error:

C:\Users\..\node_modules\selenium-webdriver\lib\error.js:524

    let err = new ctor(data.message)              ^


SessionNotCreatedError: session not created: Chrome failed to start: exited normally.

  (session not created: DevToolsActivePort file doesn't exist)

  (The process started from chrome location C:\Users\..\src\src.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

    at Object.throwDecodedError (C:\Users\..\node_modules\selenium-webdriver\lib\error.js:524:15)

    at parseHttpResponse (C:\Users\..\node_modules\selenium-webdriver\lib\http.js:601:13)

    at Executor.execute (C:\Users\..\node_modules\selenium-webdriver\lib\http.js:529:28) 

    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {

  remoteStacktrace: '\tGetHandleVerifier [0x00007FF6F8F27892+54818]\n' +

    '\t(No symbol) [0x00007FF6F8E96AC2]\n' +

    '\t(No symbol) [0x00007FF6F8D4DA3B]\n' +

    '\t(No symbol) [0x00007FF6F8D7C202]\n' +

    '\t(No symbol) [0x00007FF6F8D7802E]\n' +

    '\t(No symbol) [0x00007FF6F8DB67FB]\n' +

    '\t(No symbol) [0x00007FF6F8DAE883]\n' +

    '\t(No symbol) [0x00007FF6F8D83691]\n' +

    '\t(No symbol) [0x00007FF6F8D848D4]\n' +

    '\tGetHandleVerifier [0x00007FF6F928B992+3610402]\n' +

    '\tGetHandleVerifier [0x00007FF6F92E1860+3962352]\n' +

    '\tGetHandleVerifier [0x00007FF6F92D9D4F+3930847]\n' +

    '\tGetHandleVerifier [0x00007FF6F8FC3646+693206]\n' +

    '\t(No symbol) [0x00007FF6F8EA1628]\n' +

    '\t(No symbol) [0x00007FF6F8E9D934]\n' +

    '\t(No symbol) [0x00007FF6F8E9DA62]\n' +

    '\t(No symbol) [0x00007FF6F8E8E113]\n' +

    '\tBaseThreadInitThunk [0x00007FF97A62257D+29]\n' +

    '\tRtlUserThreadStart [0x00007FF97B94AA78+40]\n'

}


Appreciate any help.


Thanks,

Mukesh


Roger Wang

unread,
Nov 7, 2023, 12:00:16 PM11/7/23
to Mukesh, nw.js
NW makes some changes to selenium. Maybe it's what you need:
--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwjs-general/75755da8-e4f0-4dbd-a97b-d86ae3eac1aen%40googlegroups.com.

Ayush C.

unread,
Nov 11, 2023, 3:18:05 PM11/11/23
to nw.js
https://github.com/nwutils/nw-test-suite/blob/main/nw/window/test.js
Here's an example of testing NW.js via Selenium using JavaScript. Hope this helps!
Reply all
Reply to author
Forward
0 new messages