Launch a batch file or a .exe from Selenium WebDriver

10,526 views
Skip to first unread message

Radhika Tellakula

unread,
Jun 27, 2013, 5:16:04 PM6/27/13
to seleniu...@googlegroups.com
My task is to launch an executable, directly or by starting a batch file from selenium that will open a Browser application. Anyone knows if Selenium WebDriver provides this capability.
The application I am trying to automate is Windows based running as a service. When the app is launched, it opens a browser session that is an abridged form of a browser with no url.
I need to get control of that browser session and configure the required parameters. I am looking for a way to get handle of browser with selenium. Since Selenium will allow handle to the browser session that is initiated either by RemoteWebDriver or WebDriver, my idea was to launch the app from selenium API so that I can continue my configuration. The app can be launched by running the .exe with the url and can be started with a windows batch file.
I would like to get this working with Selenium as all my old automation runs wonderfully with Selenium WebDriver on FF/Chrome/IE.
Has anyone worked on a similar application and has found solution.

priyanka...@gmail.com

unread,
Jun 28, 2013, 6:20:23 AM6/28/13
to seleniu...@googlegroups.com
Hi Radhika,

In your case ,You can Automate your Windows bases operation using AutoIT ,U can convert it in .exe and u can run that file using Selenium Webdriver .

Following is code to execute .exe file 

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Login

            IWebDriver driver = new InternetExplorerDriver(@"C:\Users\Administrator\Documents\IEDriverServer_Win32_2.32.3");
            driver.Navigate().GoToUrl("http://192.192.6.153/CRMPOC/main.aspx");
            Thread.Sleep(4000);
            Process.Start("C:\\Users\\Administrator\\Desktop\\http_IE8.exe");

}
}
}

Let me know if any queries.

Thanks
Priyanka

Ram Maram

unread,
Jun 29, 2013, 12:38:03 AM6/29/13
to seleniu...@googlegroups.com
Hi,

as we know, selenium doesnot supports windows application, so for that we need help of auto it, Auto it script look likes .exe file, there is no function to call .exe or .bat files in web driver or selenium. wee need to use

Process process=Runtime.getRuntime.exec("file path of exe or .bat files");
process.waitFor();

or else

user process builde class to call .exe or .bat files


Please let me know if you any concenrs.

Thanks,
Ram.




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/93bf18c4-4272-4311-9445-1b16d809ac36%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks and Regards,
M.Sitaramireddy.

Radhika Tellakula

unread,
Jul 1, 2013, 3:54:12 PM7/1/13
to seleniu...@googlegroups.com
Thanks for the reply, Priyanka.  I have tried the AutoIT approach, using an autoIT script to launch the application (which is actually a browser based off on Trident Server using IE). After the application is launched, I want to get a handle of the browser session, which is where I am stuck at. AutoIt will launch the Trusted Browser with the code snippet that you have provided, but after launching it, how can Selenium take control of the browser session, since the browser instance is not launched by selenium,.  I need to configure parameters before moving forward with the tests.


Radhika

Jim Evans

unread,
Jul 1, 2013, 4:17:02 PM7/1/13
to seleniu...@googlegroups.com
Attaching to an existing browser session (including an embedded browser inside an application) isn't supported by WebDriver in general, and is not supported at all in the IE driver in particular. The architecture of the IE driver makes it theoretically possible to get this to work, but it's not exposed functionality, and isn't likely to be exposed anytime in the near future.

Don Kleppinger

unread,
Nov 24, 2013, 4:59:23 PM11/24/13
to seleniu...@googlegroups.com
I need to do something similar but I only want to add extra parameters to my firefox startup command line.   If I add them to the .exe browser path they get ignored.  I need to do this because this a customized version of firefox that requires the -ini pathto\application.ini parameter.

tanu sharma

unread,
Jan 12, 2016, 3:58:10 AM1/12/16
to Selenium Users
Hi,

can anybody help here.I have the same problem.

I have to launch an .exe. After launch, the application opens as a chrome browser(the code of the application is written in node.js).
I am able to launch the app using  Process p = Runtime.getRuntime().exec("yor exe path");

But how can I now switch over to the window of this app.

Krishnan Mahadevan

unread,
Jan 12, 2016, 4:07:35 AM1/12/16
to Selenium Users
You cannot switch to the browser instance that was not spawned by WebDriver code.

You will be able to use the webdriver provided apis against a browser and interact with a web application only if the web browser was spawned by the webdriver apis [ using new FirefoxDriver()/new InternetExplorerDriver()/new ChromeDriver()/new RemoteWebDriver() ]. If you using the java APIs to spawn a browser then you are on your own.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

David

unread,
Jan 12, 2016, 12:21:23 PM1/12/16
to Selenium Users
Renewing an old thread post here? FYI, I recall reading info that WatiN allows for reusing an existing browser that was not launched by WatiN. Unfortunately, this is similar to but is not Selenium WebDriver: http://watinandmore.blogspot.com/2010/01/browserattachto-and-iattachto.html.

In the use cases described in this thread, you'll have to use other tools. WatiN is one option. If you'd like to keep usage of the WebDriver API but automate the externally launched browser app with a different tool, some alternative considerations are: https://github.com/daluu/autoitdriverserverhttps://github.com/daluu/autopydriverserver

Arpit Goel

unread,
Mar 30, 2017, 9:35:04 AM3/30/17
to Selenium Users
and how can we execute .exe file using selenium in javascript???? 

David

unread,
Mar 30, 2017, 3:22:03 PM3/30/17
to Selenium Users
Arpit, you can't. But you can using Selenium APIs if you run AutoItDriverServer or AutoPyDriverServer and connect to it via RemoteWebDriver. If need to interact with browser too, can combine one instance of (regular) Selenium and an instance of AutoIt/AutoPyDriverServer to manipulate the exe/GUI and the browser in same test.
Reply all
Reply to author
Forward
0 new messages