Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

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


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