Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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.
avatar
mfsi_sitamj
Posts : 6
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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
avatar
mfsi_sitamj
Posts : 6
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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 Sad .

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.
avatar
mfsi_sitamj
Posts : 6
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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.
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Anybody any idea abt how to select upload file in webdriver Empty 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
Sponsored content

Anybody any idea abt how to select upload file in webdriver Empty Re: Anybody any idea abt how to select upload file in webdriver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum