We all know that, Selenium will not support window based elements. To upload/download we need to use some third party tools.
Below post explains how to upload a file from local drive using AutoIt.
1.Dowload AutoIt from link : http://www.autoitscript.com/site/autoit/downloads/
2.Install it
(This code is to select a file from window after clicking on browse button from web page, After this we have click on upload button from web page)
WinWaitActive("File Upload")
Send("C:\Temp\Test.txt")
Send("{ENTER}")
Write this code in Notepad and save the file as “Upload.au3”
Right Clicked on the created file “Upload.au3” and click on Compile Script.
You will get “Upload.exe” file
Call this file in Selenium script or in RFT script as below:
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Ramesh Upload.exe");
Sample Selenium Code using AutoIt upload:
public class Upload {
public WebDriver driver;
@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Test
public void testTestScenario1() throws Exception
{
driver.get("http://www.2shared.com/");
driver.findElement(By.id("upField")).click();
Thread.sleep(5000);
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Upload.exe");
driver.findElement(By.xpath("//input[@title='Upload file']")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
Below post explains how to upload a file from local drive using AutoIt.
1.Dowload AutoIt from link : http://www.autoitscript.com/site/autoit/downloads/
2.Install it
(This code is to select a file from window after clicking on browse button from web page, After this we have click on upload button from web page)
WinWaitActive("File Upload")
Send("C:\Temp\Test.txt")
Send("{ENTER}")
Write this code in Notepad and save the file as “Upload.au3”
Right Clicked on the created file “Upload.au3” and click on Compile Script.
You will get “Upload.exe” file
Call this file in Selenium script or in RFT script as below:
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Ramesh Upload.exe");
Sample Selenium Code using AutoIt upload:
public class Upload {
public WebDriver driver;
@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Test
public void testTestScenario1() throws Exception
{
driver.get("http://www.2shared.com/");
driver.findElement(By.id("upField")).click();
Thread.sleep(5000);
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Upload.exe");
driver.findElement(By.xpath("//input[@title='Upload file']")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
No comments:
Post a Comment