Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Anybody any idea abt how to select upload file in webdriver

View previous topic View next topic Go down

Anybody any idea abt how to select upload file in webdriver

Post by Arahant on 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.

Arahant
Active particpant
Active particpant

Posts : 23
Join date : 2012-02-29

Back to top Go down

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

Post by mfsi_sitamj on 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

mfsi_sitamj

Posts : 6
Join date : 2012-02-29

Back to top Go down

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

Post by Arahant on 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

Arahant
Active particpant
Active particpant

Posts : 23
Join date : 2012-02-29

Back to top Go down

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

Post by mfsi_sitamj on 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

mfsi_sitamj

Posts : 6
Join date : 2012-02-29

Back to top Go down

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

Post by Arahant on 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.

Arahant
Active particpant
Active particpant

Posts : 23
Join date : 2012-02-29

Back to top Go down

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

Post by mfsi_sitamj on 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

mfsi_sitamj

Posts : 6
Join date : 2012-02-29

Back to top Go down

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

Post by Arahant on Tue Mar 20, 2012 4:33 pm

Thanks for reply.

I will try and let you know.

Arahant
Active particpant
Active particpant

Posts : 23
Join date : 2012-02-29

Back to top Go down

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

Post by Arahant on Mon Apr 02, 2012 4:09 pm

Hi Sitam,

Provided above code is not working. (:

Thanks,
Arahant

Arahant
Active particpant
Active particpant

Posts : 23
Join date : 2012-02-29

Back to top Go down

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

Post by Sponsored content Today at 6:06 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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