{"id":4920,"date":"2020-09-21T19:45:40","date_gmt":"2020-09-21T14:15:40","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=4920"},"modified":"2025-04-02T10:03:12","modified_gmt":"2025-04-02T14:03:12","slug":"file-upload-autoit-usage-with-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/file-upload-autoit-usage-with-selenium-webdriver\/","title":{"rendered":"File Upload &#8211; AutoIT usage with Selenium Webdriver"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>What is AutoIt?<\/strong><\/h2>\n\n\n\n<p>AutoIt is a freeware scripting language implemented for windows GUI automation. Using the combination of simulated keyboard, mouse movement, and window\/control manipulation to automate tasks not possible using only selenium. An AutoIt automation script can be converted into compressed, stand-alone executable applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why Use AutoIt?<\/strong><\/h3>\n\n\n\n<p>Selenium is an open-source tool that is used to automate web-based applications on different browsers but cannot handle any non-browser and non-HTML elements. To handle such elements like the Windows <a href=\"https:\/\/en.wikipedia.org\/wiki\/Authentication\" data-type=\"link\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Authentication\" rel=\"nofollow noopener\" target=\"_blank\">authentication<\/a> box, File upload dialog box, and any other non-browser interaction we use AutoIt.<\/p>\n\n\n\n<p>In this tutorial, we will learn how to upload a file using AutoIt in selenium web driver. Here we need three tools&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Selenium Webdriver<\/li>\n\n\n\n<li>AutoIT editor and element identifier<\/li>\n\n\n\n<li>The window you want to automate<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to download and install AutoIT<\/strong><\/h2>\n\n\n\n<p><strong>Step 1: <\/strong>Go to the link <a href=\"https:\/\/www.autoitscript.com\/site\/autoit\/downloads\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/www.autoitscript.com\/site\/autoit\/downloads\/<\/a><\/p>\n\n\n\n<p><strong>Step 2:<\/strong> Mouse-hover to AutoIt Install dropdown.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/-kxapZ06oayObHSYlx5djeTUMPt0x6RxSDHwulnkQ4Gcf-4h2Y2b5PKl0IY0rFE04q23Lo_-QuL0FP8VtsCBAeDSDGl-N8MRbQ-LVbGmrLjWtOEZ-jHwaZjMsihsaBqG9G0zi1A5k8lw40jaSw\" alt=\"Autoit.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 3:<\/strong>&nbsp;Click on the Downloads option under AutoIt.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/EcE0e-CytKSBdenFQ6YE9G7CuFwZmx4CbvN6-qD2C_LMvQJKMibfPrDISwGvvGoxit6nLTnRPbjolOZfrqh1YLpk2ACr5K3nqkly5uyd_BpCEMewwS9pohZDf7psYyPvuGU9kQZMqY_bC5e_Cw\" alt=\"autoitdownload.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 4<\/strong>: Click on the &#8216;Download AutoIt&#8217; button to download AutoIt.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/NVh7XmNah7k8Q8oGlD_Px6OnXuk_1Dt32tt8v2i6YzWEfAxSzKJ10xtJtj4QB9lUO6eNyyV9fp5E-yXM37dUMyTEX7EMTD8dnCIw0j-RNOOcItf1CJczVkCuXkyMRWuJ8GM2f3N0J3wRzXRRmQ\" alt=\"autoitversion.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 5<\/strong>: Now download &#8220;Autoit editor&#8221; by clicking on &#8216;Editor Downloads&#8217;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/mFwAwjv-u7auCyFPpNwi4IUu9cGQXiMYJPNbWU1iEcJlXyQhz8llmqgBlLKlYyMLIcJtpP_hXwOQAvEGxBvXq6eYL_24go-yQXVk_tFJQfw6nOcyO8dt1XXjKhKGPk2VreDXd0W71TCaw0Je8Q\" alt=\"editor.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 6:&nbsp;<\/strong>As shown below click on the link.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/LweWwDiQbKAiY-xUZYiR3dJLGetvYx768yIVRe68BD7f9OoJmEi1Phn3o-LV42SgYsUkl4am_X6hpFa30WFkZw-U69b6Du06vA9mqNAjB505bvo0LpAUw2J6k4DBU9mLfu8d7_ern5aTDUyJgw\" alt=\"zipeditor.PNG\" title=\"\"><\/figure>\n\n\n\n<p>After download you will get two setup files, The first is&nbsp;<strong>AutoIt version 3<\/strong>&nbsp;setup and the second is&nbsp;<strong>SciTE4AutoIt3<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Bqds3bamsrnK1qi0SjZnGCOeFNcPQLUUEWtrimsRw_z_4UBWnZltYt9W6pEz3uo3OoQ_WeYJ-5uOJSexQlW44B1hlf_3bkbtfxgrSE_Tcg_UbCtkhItPdgEVICoHAYRwG11P_Gt0alLR0YZDiQ\" alt=\"downloads.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 6<\/strong>: Installing AutoIT-Click on both AutoIT setup.<\/p>\n\n\n\n<p><strong>Step 7<\/strong>: After installation completion &#8211; open up AutoIT Editor.<\/p>\n\n\n\n<p><code>Go to 'C:\\Program Files (x86)\\AutoIt3\\SciTE'<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/X5NgBt9bZovJ2bc2n-AmWmZraZJ0y1OLxXtZkp7I_bXUpng6KCrtNYB6Sf7nkcbj3NVnmZhJFgCWj9tZndUb380437eA1IN9jVdoiHnms0eg6Pgyv4w6xoJU1DogiTbQqSHSY9n1Uawa3BjJCA\" alt=\"autoitexe.PNG\" title=\"\"><\/figure>\n\n\n\n<p>Click on &#8216;SciTE.exe&#8217; file, the AutoIT editor opens as shown in the below screen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/_oV5wFJ0mmX9iMHnwJ0_qOGeu8E8W6i0I588kI_yS9uiSfFbivMKWLFZagxPC8cKx60HeIMaUBM3FuHvFLqltvSrGfHK-0tSJOAl7jfEgTyTc1xjZ07ZJrAM2rK8GzIy8shD0O0rM6dnrDhn7Q\" alt=\"exeopen.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 8<\/strong>: Now opens the element Identifier.<\/p>\n\n\n\n<p>Go to &#8216;C:\\Program Files (x86)\\AutoIt3\u2019<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/ZNtihU2qnwQpLoXI6k7vfdNPYE_1eAI-Tj8aG92fdPMU7glHxxvrYXl9BV6dIWXw0FBBLXe7GJ5PaNWpvudtl4jCTy6kBbKvpUFUc3-nIBMBGmoUSHxGuEDZOL7QFXRoBI8mIinp2g1ALl0BDQ\" alt=\"autoitinfo.PNG\" title=\"\"><\/figure>\n\n\n\n<p>And click on &#8216;Au3Info.exe&#8217; file, the element identifier opens a screen as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/xM3BekXU-utT4k0JPHG5zTSDfT5D01FCOpraQiYJAszgEBLRxJsv57ZsZluiCPWrYSOqsG0LNGx81m6Fb81DOVOSRRxkKNjKbo4_m5LSVsz5k9HW51hkSMvzSSaDK1aKuKrxhwnwm0PvDnZNUg\" alt=\"frozenautoit.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;Once this element identifier is done you need to close it manually as it will not close automatically.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>File Upload using SendKeys method&nbsp;in Selenium WebDriver:<\/strong><\/h4>\n\n\n\n<p>We can easily achieve this by using&nbsp;<em>sendkeys<\/em>&nbsp;method, text box locating, and by using&nbsp;the <em>sendkeys <\/em>method&nbsp;we need to set the path of the file and click on the submit button.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> htmldriver;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n\n<strong>public<\/strong> <strong>class<\/strong> Upload {\n\n<strong>public<\/strong> <strong>static<\/strong> <strong>void<\/strong> main(String&#91;] args) <strong>throws<\/strong> InterruptedException {\n\/\/ <strong>TODO<\/strong> Auto-generated method stub\n\/\/Instantiation of driver object. To launch Firefox browser\nSystem.<em>setProperty<\/em>(\"webdriver.gecko.driver\",\"F:\\\\drivers\\\\geckodriver.exe\");&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp; WebDriver driver = <strong>new<\/strong> FirefoxDriver();\n\/\/To open URL \"http:\/\/softwaretestingmaterial.com\"\ndriver.get(\"https:\/\/www.timesjobs.com\/candidate\/register.html?\");\n\/\/Locating 'browse' button\nWebElement browse =driver.findElement(By.<em>id<\/em>(\"resumeFile_basic\"));\n\/\/ By using Sendkeys method pass the path of the file to be uploaded Thread.<em>sleep<\/em>(3000);\nbrowse.sendKeys(\"D:\\\\Testing\\\\UploadFile.txt\");\n\/\/This close method will close the browser window\ndriver.close();\n}\n\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Upload the file AutoIt Script in Selenium WebDriver:<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the Programs \u2013&nbsp;<em>Autoit<\/em>&nbsp;tool \u2013 SciTE Script Editor and include&nbsp;the below mentioned&nbsp;<em>AutoIt&nbsp;<\/em>script&nbsp;in&nbsp;<em>Autoit<\/em>&nbsp;editor and save it as \u2018UploadFile.au3\u2019 in your system<\/li>\n\n\n\n<li>Convert it as \u2018UploadFile.exe\u2019<\/li>\n\n\n\n<li>In Eclipse, add the below mentioned Selenium Script and run<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Open SciTE Script editor and add the below mentioned&nbsp;<em>AutoIt script and s<\/em>ave it&nbsp;as \u2018UploadFile.au3\u2019 in your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>AutoIt<em>&nbsp;S<\/em>cript:<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>WinWaitActive(\"File Upload\")\nSend(\"D:\\Testing\\UploadFile.txt\")\nSend(\"{ENTER}\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>AutoIt<\/strong><strong><em>&nbsp;S<\/em><\/strong><strong>cript Explanation:<\/strong><\/h2>\n\n\n\n<p><code>Line 1:&nbsp;<em>WinWaitActive(\u201cFile Upload\u201d)<\/em><\/code><\/p>\n\n\n\n<p>Above the line of code changes&nbsp;the focus of cursor on&nbsp;the Window popup box to upload the file.<\/p>\n\n\n\n<p>When using&nbsp;Mozilla Firefox \u2018<em>File Upload<\/em>\u2018 is the name of the popup window.&nbsp;<\/p>\n\n\n\n<p><code>Line 2:&nbsp;<em>Send(\u201cPath of the document\u201d)<\/em><\/code><\/p>\n\n\n\n<p>Once the popup window is active, it will set the&nbsp;path of the document which needs to be uploaded<\/p>\n\n\n\n<p><code><em>Send(\u201cD:\\Testing\\UploadFile.txt\u201d)<\/em><\/code><\/p>\n\n\n\n<p>Line 3:&nbsp;<em>Send(\u201c{ENTER}\u201d)<\/em><\/p>\n\n\n\n<p>It clicks&nbsp;on Open button that will upload the document<\/p>\n\n\n\n<p><strong>Step 2:<\/strong>&nbsp;Once the file is saved, we need to convert the \u2018UploadFile.au3\u2019 to \u2018UploadFile.exe\u2019. To prepare this we need to compile the \u2018UploadFile.au3\u2019<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> Right-click on the file \u2018UploadFile.au3\u2019 and click on \u2018Compile Script(x64)\u2019 to generate an executable file \u2018UploadFile.exe\u2019<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/UslC4wTBIAJmcDfZAqBy5kvisujkNbPpiOtVJmVtotl8h6DCw5Pir3ampWbAWnph00-YqCQczAX263VBg9O1mzu7RNuyTetaGukX-OJ_x0pnLYlN0K58HrCe7AT-l1aWG5AFCRLRseJOQNckYg\" alt=\"compilescript.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 4:<\/strong>&nbsp;In Eclipse, add the below Selenium Script and run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> htmldriver;\n\n<strong>import<\/strong> java.io.IOException;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n\n<strong>public<\/strong> <strong>class<\/strong> Upload1 {\n\n<strong>public<\/strong> <strong>static<\/strong> <strong>void<\/strong> main(String&#91;] args) <strong>throws<\/strong> IOException {\n\/\/ <strong>TODO<\/strong> Auto-generated method stub\n\/\/Instantiation of driver object. To launch Firefox browser\nSystem.<em>setProperty<\/em>(\"webdriver.gecko.driver\",\"F:\\\\drivers\\\\geckodriver.exe\");&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp; WebDriver driver = <strong>new<\/strong> FirefoxDriver();\n\/\/To open URL \"http:\/\/softwaretestingmaterial.com\"\ndriver.get(\"https:\/\/www.timesjobs.com\/candidate\/register.html?\");\n\/\/Locating 'browse' button\nWebElement browse =driver.findElement(By.<em>id<\/em>(\"resumeFile_basic\"));\n\/\/To click on the 'browse' button\nbrowse.click();\n\/\/To call the AutoIt script\nRuntime.<em>getRuntime<\/em>().exec(\"D:\\\\Testing\\\\AutoIt\\\\Uploadfile.exe\");\n\/\/'close' method is used to close the browser window\ndriver.close();\n}\n\n}<\/code><\/pre>\n\n\n\n<p>In the above Selenium Script, After&nbsp;clicking on the browser button&nbsp;we call the&nbsp;<em>AutoIt&nbsp;<\/em>Script which transfers the <a href=\"https:\/\/www.h2kinfosys.com\/blog\/popups-and-alerts-in-selenium\/\" data-type=\"link\" data-id=\"https:\/\/www.h2kinfosys.com\/blog\/popups-and-alerts-in-selenium\/\">Windows popup<\/a> box and uploads the required file.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Runtime.getRuntime().exec(\"File Path of AutoIt.exe\");\n\nRuntime.getRuntime().exec(\u201cD:\\\\Testing\\\\AutoIt\\\\Uploadfile.exe\u201d);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion:<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download and install the Element Identifier and AutoIT editor.<\/li>\n\n\n\n<li>Open the site to do the operation.<\/li>\n\n\n\n<li>Identify the elements of the file uploader window using the Element Identifier.<\/li>\n\n\n\n<li>With the help of Element identifier, we will prepare AutoIT script in the editor&nbsp;<\/li>\n\n\n\n<li>Autoit script is written in the selenium webdriver script.<\/li>\n\n\n\n<li>Execute the selenium script.<\/li>\n<\/ul>\n\n\n\n<p>In conclusion, integrating AutoIt with Selenium WebDriver provides a reliable solution for handling file upload scenarios and other non-browser interactions. By automating system-level tasks, this combination enhances the scope of your test automation framework. Gaining expertise in such integrations is essential for advanced testing, and <a href=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\" data-type=\"link\" data-id=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\">Selenium certification<\/a> offer in-depth guidance on mastering these techniques. Enroll in a course today to enhance your skills and take your automation expertise to the next level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Call to Action<\/h2>\n\n\n\n<p>Are you ready to tackle complex automation challenges like file uploads and non-browser interactions? Mastering AutoIt usage with Selenium WebDriver is a game-changer for creating robust and versatile automation frameworks. At H2K Infosys, we provide expert-led training that dives deep into integrating tools like AutoIt to handle system-level tasks seamlessly. With real-world projects and hands-on practice, you&#8217;ll gain the confidence to automate even the most complex scenarios effectively.<\/p>\n\n\n\n<p><strong>Join H2K Infosys and Advance Your Career<\/strong><br>Don&#8217;t let system-level challenges hold you back in your automation journey. Enroll in our comprehensive Selenium online courses to learn how to integrate AutoIt with Selenium WebDriver for handling file uploads, pop-ups, and more. With experienced trainers, live projects, and 24\/7 support, we ensure you&#8217;re equipped to excel in the competitive field of automation testing. Take the next step toward becoming a skilled automation professional join H2K Infosys today!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is AutoIt? AutoIt is a freeware scripting language implemented for windows GUI automation. Using the combination of simulated keyboard, mouse movement, and window\/control manipulation to automate tasks not possible using only selenium. An AutoIt automation script can be converted into compressed, stand-alone executable applications. Why Use AutoIt? Selenium is an open-source tool that is [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":6885,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[1390,156,1391,45,448,51],"class_list":["post-4920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials","tag-autoit-automation-script","tag-automation-testing","tag-install-autoit","tag-selenium","tag-selenium-webdriver","tag-software-testing"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=4920"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4920\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/6885"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=4920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=4920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=4920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}