- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Anybody any idea abt how to select upload file in webdriver
Mon Mar 05, 2012 3:56 pm
Hi All,
Any body having sample code on uploading file in web driver.If so then plz paste the code.
Any body having sample code on uploading file in web driver.If so then plz paste the code.
- mfsi_sitamj
- Posts : 6
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Mon Mar 05, 2012 6:14 pm
Hi Arahant,
You can try with the following 3 lines of code :-
1)driver.findElement(By.xpath("//*[@id='file']")).clear();
2)driver.findElement(By.xpath("//*[@id='file']")).sendKeys("D:\\Selenium\\My Automation Works\\Salesforce");
3)driver.findElement(By.xpath("//[@id='editPage']/div/table/tbody/tr[7]/td[2]/input")).click();
//*[@id='file'] => xpath of the Browse field.
D:\\Selenium\\My Automation Works\\Salesforce => Path of the file you want to upload.
//[@id='editPage']/div/table/tbody/tr[7]/td[2]/input => xpath of the upload button.
Hope this will help you.
Thanks and regards
Sitam
You can try with the following 3 lines of code :-
1)driver.findElement(By.xpath("//*[@id='file']")).clear();
2)driver.findElement(By.xpath("//*[@id='file']")).sendKeys("D:\\Selenium\\My Automation Works\\Salesforce");
3)driver.findElement(By.xpath("//[@id='editPage']/div/table/tbody/tr[7]/td[2]/input")).click();
//*[@id='file'] => xpath of the Browse field.
D:\\Selenium\\My Automation Works\\Salesforce => Path of the file you want to upload.
//[@id='editPage']/div/table/tbody/tr[7]/td[2]/input => xpath of the upload button.
Hope this will help you.
Thanks and regards
Sitam
- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Tue Mar 06, 2012 6:27 pm
Hi Sitam,
Thanks for your reply.
I tried with provided code but not succeeded .The issue is
1)driver.findElement(By.xpath("//*[@id='file']")).clear(); ----> For this throwing error is Element must be user-editable in order to clear it.
If you comment above line then issue is in browser
Server Error in '/PRO_V1' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Thanks,
Arahant
Thanks for your reply.
I tried with provided code but not succeeded .The issue is
1)driver.findElement(By.xpath("//*[@id='file']")).clear(); ----> For this throwing error is Element must be user-editable in order to clear it.
If you comment above line then issue is in browser
Server Error in '/PRO_V1' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Thanks,
Arahant
- mfsi_sitamj
- Posts : 6
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Wed Mar 14, 2012 3:49 pm
Can you share the link of that webpage containing that uploading ?
or else if it is a live project, share the screen shot of the upload portion of the page.
Thanks
Sitam
or else if it is a live project, share the screen shot of the upload portion of the page.
Thanks
Sitam
- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Wed Mar 14, 2012 4:57 pm
Hi,
I tried to upload screen shot but unable to upload the file, saying that file should not more than 0 kb.Leave that .
would like to explain here.
That web page is having browse button,if you click on it.The upload file
path will open and select whichever file or image wish to select and
say ok on file path window that image path will placed in web
application which has upload button,once if you click on upload
button.The uploaded file will save automatically in admin section. (I
think this process will be having all most all web applications).
This scenario i need to handle in web driver. I hope you understood.In case if not please revert back the message.
I tried to upload screen shot but unable to upload the file, saying that file should not more than 0 kb.Leave that .
would like to explain here.
That web page is having browse button,if you click on it.The upload file
path will open and select whichever file or image wish to select and
say ok on file path window that image path will placed in web
application which has upload button,once if you click on upload
button.The uploaded file will save automatically in admin section. (I
think this process will be having all most all web applications).
This scenario i need to handle in web driver. I hope you understood.In case if not please revert back the message.
- mfsi_sitamj
- Posts : 6
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Tue Mar 20, 2012 4:00 pm
Hi Arahant,
Try the following snippet :-
import java.io.File;
import java.net.URISyntaxException;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class File_upload {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.sendspace.com/");
File file = null;
try {
file = new File(File_upload.class.getClassLoader().getResource("file.txt").toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Assert.assertTrue(file.exists());
WebElement browseButton = driver.findElement(By.xpath("//*[@id='upload_file']"));
browseButton.sendKeys(file.getAbsolutePath());
}
}
Thanks
Sitam
Try the following snippet :-
import java.io.File;
import java.net.URISyntaxException;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class File_upload {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.sendspace.com/");
File file = null;
try {
file = new File(File_upload.class.getClassLoader().getResource("file.txt").toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Assert.assertTrue(file.exists());
WebElement browseButton = driver.findElement(By.xpath("//*[@id='upload_file']"));
browseButton.sendKeys(file.getAbsolutePath());
}
}
Thanks
Sitam
- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Tue Mar 20, 2012 4:33 pm
Thanks for reply.
I will try and let you know.
I will try and let you know.
- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Re: Anybody any idea abt how to select upload file in webdriver
Mon Apr 02, 2012 4:09 pm
Hi Sitam,
Provided above code is not working. (:
Thanks,
Arahant
Provided above code is not working. (:
Thanks,
Arahant
Permissions in this forum:
You cannot reply to topics in this forum