Skip to main content

Automate desktop/electron application using selenium


As We all know that using selenium, we cannot automate desktop-based application.
But that's not 100% true😊, Because using selenium we can automate desktop application which is build in electron and nodeJS.

Now what is electron?
Electron is a framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It takes care of the hard parts, so you can focus on the core of your application.

Now a day’s there are many good companies using electron for there product few of them are
·         Slack,
·         WordPress desktop app
·         Visual Studio Code (VS Code)
·         Skype
And there many more. electron application basically looks like below image in which we can have developer tool to inspect elements.For developer tool you need to press ctl+alt+i it open just like chrome browser but  still your not able to open developer tool then need to ask your deployment team to enable developer tool from there code its self.



If you want to automate such type of applications using selenium java then you simply must follow following steps.
System.setProperty("webdriver.chrome.driver", "path of the exe file\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
/* setting electron binary path */
options.setBinary("C:\Users2\ElectronAPIDemos.exe");
ChromeDriverService chromeservices = new ChromeDriverService.Builder().build();
driver = new ChromeDriver(chromeservices, options);

That's it and it will launch your desktop application and rest of things that will work as normal selenium.

Thanks, For any query mail me on qaautomation365@gmail.com or you can add comments below.


















Comments

Anonymous said…
nice post
Unknown said…
Driver.findelement is not working.please help
Unknown said…
for Driver.findelement what exception you are getting ??
Unknown said…
i am getting this error please help me
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
Prathap said…
Thanks for the post. But I am also getting the issue "org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
"

Could you please let us know if any solutions?
Ajay said…
Hi Prathap,

you need to check with your DEV team and ask them to activate the DEV tool