- kaykay81
- Posts : 3
Join date : 2011-09-27
How to automate upload image functionality using Selinium IDE
Thu Nov 10, 2011 6:33 pm
Hi all,
I want to automate upload image functionality using Selinium IDE.
Can any one help me regarding it ????
The upload is similar to attach files in mail..
Thanks & Regards,
KayKay
I want to automate upload image functionality using Selinium IDE.
Can any one help me regarding it ????
The upload is similar to attach files in mail..
Thanks & Regards,
KayKay
- freeskyAmateur
- Posts : 72
Join date : 2011-04-13
Re: How to automate upload image functionality using Selinium IDE
Fri Nov 11, 2011 3:53 pm
I'm afraid selenium ide can't do that. maybe u can use selenium with AutoIT. I refer to somebody's article, hope to help you.
Recently,I had the challenge of writing some automation for a workflow
which includeduploading a file, and then downloading a file later in the
workflow. The team with whom I am working had used some Selenium
fortheir tests, and preferred to keep doing so, if possible, but their
effortsprior to my arrival on the team to get the upload/download
portions of the codeworking with Selenium had been unsuccessful.
The problem basically boils down to twopoints:
The JavaScript interpreters in mostbrowsers have specific protections built in to prevent
JavaScripts from filling in “file”fields, such that when they tried
“type” “filefield” “myfile.txt”, nothingwould happen in the browser.
When attempting to use the click commandon the “browse”
buttonof the field, moreover, causes a modal dialog which holds focus
such that theclick command does not return, because it is waiting for
feedback from thebrowser, until the modal file picking dialog closes.
So,
you can’t type into the file field,and you can’t click on it to open
the file dialog, because even if you can typeinto it, using native key
pressing, or another automation tool such as AutoItor AutoHotKey, which
can grab window focus, and send typing events, you’restill kind of
hosed, because until your script returns from the click event,which it
won’t because there’s this modal window stuck out there, blocking it. KeyDown and KeyUp don’t triggerany action in the control, good or bad.
So what to do?
Well, there are solutions, evenfairly easy ones, but they are probably
going to involve at least a littleplatform and browser-specific kludges,
which you can hopefully write intofunctions, and then never worry about
again. In some browsers, I was ableto use the focus(locator) command,
and then do native system typing withKeyPressNative, or AutoIt, which
allows me to grab the appropriate windowfirst, and simply send the
desired text. However, in some browsers, thiswill not work, as the
field will bring up the dialog when you begin to typeinto the field.
Below, you can find my solution.
System.out.println(”focusingon file field”);
selenium.focus(”uploadfile”);
if(T1.Browser.startsWith(”*ie”))
{
System.out.println(”Doingthe ie tabbing”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyDownNative(java.awt.event.KeyEvent.VK_SHIFT+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyUpNative(java.awt.event.KeyEvent.VK_SHIFT+ “”);
System.out.println(”Submittingfile: ” + fname);
Processfileup = Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe C:\\testfiles\\scripts\\submitFileName.au3\”" + fname + “\”");
fileup.waitFor();
selenium.click(”ok”);
}else {
if(T1.Browser.startsWith(”*firefox”))
{
getSystemFocus(”PCMS”);
selenium.focus(”uploadfile”);
System.out.println(”Doingthe firefox tabbing”);
selenium.setSpeed(”200″);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_SPACE+ “”);
getSystemFocus(”PCMS”);
System.out.println(”SpacePressed”);
System.out.println(”Submittingfile: ” + fname);
Processfileup
= Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe
C:\\testfiles\\scripts\\submitFileNameFF.au3\”"
+ fname + “\”");
fileup.waitFor();
selenium.focus(”ok”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_SPACE+ “”);
System.out.println(”Dismissingthe security warning”);
Processsecwarning
= Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe
C:\\testfiles\\scripts\\secwarning.au3″);
secwarning.waitFor();
System.out.println(”Dismissingthe security warning”);
selenium.setSpeed(”1200″);
}
There are a couple of small problems withthis solution as a general solution, but it does work for multiple browsers onWindows.
Not the leastproblem is that this will fail when running on a non-local
RC server. That can be gotten around by calling psexec or some similar
command on thehostname of the rc server, but this works only in a
Windows setup. Fornon-windows machines, a similar strategy could be
done, and you could probablyeliminate AutoIt and any outside tool by
calling keyPressNative commands foreach character of the file string,
but you may run into difficulties withsystem focus of the window.
What
would be ideal is a java tool whichcan grab window focus, and then type
in the appropriate file string, given asparameters, but I wasn’t able
to find or implement both of these requirementsin sufficient time.
Recently,I had the challenge of writing some automation for a workflow
which includeduploading a file, and then downloading a file later in the
workflow. The team with whom I am working had used some Selenium
fortheir tests, and preferred to keep doing so, if possible, but their
effortsprior to my arrival on the team to get the upload/download
portions of the codeworking with Selenium had been unsuccessful.
The problem basically boils down to twopoints:
The JavaScript interpreters in mostbrowsers have specific protections built in to prevent
JavaScripts from filling in “file”fields, such that when they tried
“type” “filefield” “myfile.txt”, nothingwould happen in the browser.
When attempting to use the click commandon the “browse”
buttonof the field, moreover, causes a modal dialog which holds focus
such that theclick command does not return, because it is waiting for
feedback from thebrowser, until the modal file picking dialog closes.
So,
you can’t type into the file field,and you can’t click on it to open
the file dialog, because even if you can typeinto it, using native key
pressing, or another automation tool such as AutoItor AutoHotKey, which
can grab window focus, and send typing events, you’restill kind of
hosed, because until your script returns from the click event,which it
won’t because there’s this modal window stuck out there, blocking it. KeyDown and KeyUp don’t triggerany action in the control, good or bad.
So what to do?
Well, there are solutions, evenfairly easy ones, but they are probably
going to involve at least a littleplatform and browser-specific kludges,
which you can hopefully write intofunctions, and then never worry about
again. In some browsers, I was ableto use the focus(locator) command,
and then do native system typing withKeyPressNative, or AutoIt, which
allows me to grab the appropriate windowfirst, and simply send the
desired text. However, in some browsers, thiswill not work, as the
field will bring up the dialog when you begin to typeinto the field.
Below, you can find my solution.
System.out.println(”focusingon file field”);
selenium.focus(”uploadfile”);
if(T1.Browser.startsWith(”*ie”))
{
System.out.println(”Doingthe ie tabbing”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyDownNative(java.awt.event.KeyEvent.VK_SHIFT+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyUpNative(java.awt.event.KeyEvent.VK_SHIFT+ “”);
System.out.println(”Submittingfile: ” + fname);
Processfileup = Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe C:\\testfiles\\scripts\\submitFileName.au3\”" + fname + “\”");
fileup.waitFor();
selenium.click(”ok”);
}else {
if(T1.Browser.startsWith(”*firefox”))
{
getSystemFocus(”PCMS”);
selenium.focus(”uploadfile”);
System.out.println(”Doingthe firefox tabbing”);
selenium.setSpeed(”200″);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB+ “”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_SPACE+ “”);
getSystemFocus(”PCMS”);
System.out.println(”SpacePressed”);
System.out.println(”Submittingfile: ” + fname);
Processfileup
= Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe
C:\\testfiles\\scripts\\submitFileNameFF.au3\”"
+ fname + “\”");
fileup.waitFor();
selenium.focus(”ok”);
selenium.keyPressNative(java.awt.event.KeyEvent.VK_SPACE+ “”);
System.out.println(”Dismissingthe security warning”);
Processsecwarning
= Runtime.getRuntime().exec(”C:\\autoit\\install\\AutoIt3.exe
C:\\testfiles\\scripts\\secwarning.au3″);
secwarning.waitFor();
System.out.println(”Dismissingthe security warning”);
selenium.setSpeed(”1200″);
}
There are a couple of small problems withthis solution as a general solution, but it does work for multiple browsers onWindows.
Not the leastproblem is that this will fail when running on a non-local
RC server. That can be gotten around by calling psexec or some similar
command on thehostname of the rc server, but this works only in a
Windows setup. Fornon-windows machines, a similar strategy could be
done, and you could probablyeliminate AutoIt and any outside tool by
calling keyPressNative commands foreach character of the file string,
but you may run into difficulties withsystem focus of the window.
What
would be ideal is a java tool whichcan grab window focus, and then type
in the appropriate file string, given asparameters, but I wasn’t able
to find or implement both of these requirementsin sufficient time.
- sunny patelActive particpant
- Posts : 11
Join date : 2012-05-03
Age : 39
Location : Ahmedabad , India
Re: How to automate upload image functionality using Selinium IDE
Wed May 09, 2012 1:03 pm
Command = storeEval
Target = prompt("Please Enter Image path") //specify image path manually
Value = flImage1
Command = type
Target = name=flImage1
Value = ${flImage1}
Target = prompt("Please Enter Image path") //specify image path manually
Value = flImage1
Command = type
Target = name=flImage1
Value = ${flImage1}
Re: How to automate upload image functionality using Selinium IDE
Wed May 09, 2012 1:37 pm
Try out below code..pass your xpath of text box
into target area
then click on upload button
into target area
- Code:
command=type
target=xpath_of_text_box
value=Path_of_your_image file
then click on upload button
Permissions in this forum:
You cannot reply to topics in this forum