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
kaykay81
Posts : 3
Join date : 2011-09-27

How to automate upload image functionality using Selinium IDE  Empty 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
avatar
freesky
Amateur
Amateur
Posts : 72
Join date : 2011-04-13

How to automate upload image functionality using Selinium IDE  Empty 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.
avatar
sunny patel
Active particpant
Active particpant
Posts : 11
Join date : 2012-05-03
Age : 39
Location : Ahmedabad , India

How to automate upload image functionality using Selinium IDE  Empty 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}
rohit13
rohit13
Master
Master
Posts : 180
Join date : 2012-03-29
Age : 38
Location : INDIA
http://radical-qa.blogspot.in/

How to automate upload image functionality using Selinium IDE  Empty 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
Code:

command=type
target=xpath_of_text_box
value=Path_of_your_image file

then click on upload button
Sponsored content

How to automate upload image functionality using Selinium IDE  Empty Re: How to automate upload image functionality using Selinium IDE

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