Downloading file using selenium webdriver Is also tricky task. I accept already described how to grip file download functionality In selenium webdriver yesteryear creating custom firefox profile In THIS POST. It Is actually really long task. At house of using custom profile approach, We tin john usage AutoIt script amongst selenium webdriver to download file from whatsoever spider web page.
You volition uncovering dissimilar examine files download links on THIS PAGE which nosotros volition usage to acquire how to download file using AutoIt In selenium webdriver. We accept to perform bellow given steps to exercise selenium webdriver + AutoIt script.
In Firefox browser, Go to THIS PAGE together with click on "Download Text File" link. It volition opened upward Save file dialog amongst Open amongst together with Save File radio options.
Now you lot tin john Identify relieve file dialog properties using AutoIt Window Info tool every bit described In THIS POST. In this illustration you lot volition acquire alone dialog's belongings (Title together with class) using AutoIt Window Info tool every bit shown In bellow Image. It Is non able to recollect belongings of Save File radio selection together with OK button. So nosotros accept to usage to a greater extent than or less alternative method In our AutoIt script to conduct Save File radio selection together with click OK button.
So nosotros accept alone dialog belongings In this illustration every bit bellow.
- File Save dialog : Title = Opening Testing Text.txt, Class = MozillaDialogClass
We volition usage shape belongings In our script to conduct dialog.
Write AutoIt script to relieve file
If you lot come across In higher upward Image, Save File selection has shortcut to conduct It. We tin john conduct It using ALT + S keyboard shortcut keys. Also focus Is laid yesteryear default on OK button. So nosotros tin john press ENTER key to conduct OK. We tin john exercise both these Keystroke activity In AutoIt really easily using Send() ascendancy every bit shown In bellow script.
; expect for 8 seconds to seem download together with relieve dialog. Used shape belongings of download dialog. WinWait("[CLASS:#MozillaDialogClass]","",8) ; Perform keyboard ALT cardinal downwards + s + ALT cardinal Up activity to conduct Save File Radio push using keyboard sortcut. Send("{ALTDOWN}s{ALTUP}") ; Wait for iii seconds Sleep(3000) ; Press Keyboard ENTER button. Send("{ENTER}")
Save higher upward script In "Script To Download File.au3" format at "E:\AutoIT" location. Above script volition perform bellow laissez passer on actions.
- wait for 8 seconds to seem file saving dialog.
- Press ALT down + s + ALT upward cardinal to conduct Save File radio.
- Press Enter cardinal to conduct OK button.
Convert script In executable format
Now you lot tin john exercise executable file of higher upward script every bit described In THIS POST. After conversion, you lot volition acquire executable file "Script To Download File.exe".
CLICK HERE to download laid upward made "Script To Download File.au3" together with "Script To Download File.exe" files of AutoIt.
Now you lot tin john exercise executable file of higher upward script every bit described In THIS POST. After conversion, you lot volition acquire executable file "Script To Download File.exe".
CLICK HERE to download laid upward made "Script To Download File.au3" together with "Script To Download File.exe" files of AutoIt.
Integrate AutoIt script amongst selenium webdriver to download file
As described In THIS POST, We volition usage java Runtime.getRuntime().exec(); method to execute AutoIt script In selenium webdriver.
So our Selenium webdriver + AutoIt script to download file from spider web page Is every bit bellow.
Note : "Script To Download File.exe" file should survive located at E:\\AutoIT folder.
package AutoIt; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace shape AutoIt_Test { WebDriver driver; @BeforeTest populace void setup() throws Exception { driver =new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(" "); } @Test populace void testCaseOne_Test_One() throws IOException, InterruptedException { //Click on Download Text File link to download file. driver.findElement(By.xpath("//a[contains(.,'Download Text File')]")).click(); //Execute Script To Download File.exe file to run AutoIt script. File place = E:\\AutoIT\\ Runtime.getRuntime().exec("E:\\AutoIT\\Script To Download File.exe"); } }
Now If you lot run higher upward script, It volition download Text file automatically. At the halt of script execution, file volition survive downloaded every bit shown In bellow Image.
This agency you lot tin john download whatsoever file from spider web page.