PDA

View Full Version : Selenium and File Upload Field



danguba
8 Oct 2009, 5:23 AM
Hi everyone.
I have a problem with automatic testing using Selenium IDE. I need to upload a file but Selenium seams unable to perform click on browse button. Using http://www.extjs.com/deploy/dev/examples/form/file-upload.html I can focus browse button but firing selenium click or clickOn event don't produce anything. Am I doing something wrong or is this some Selenium IDE limitation? Any help will be appreciated

Condor
8 Oct 2009, 6:36 AM
I always thought it was a limitation of browsers, but it seems that somebody actually found a way to bypass the security restriction (http://cakebaker.42dh.com/2006/03/29/file-upload-with-selenium/) in Firefox.

danguba
20 May 2010, 2:50 AM
Finally solved it. It looks like Ext is masking regular upload field with its own. So by selecting the original and then using Selenium type to enter absolute path to file everything works.

kashinath
6 Jan 2011, 4:00 AM
Hi danguba,
can u please paste the code of how to click on browse button. Because i am also unable to click on Browse button in my web application. I tried lot of methods but could not reach to solution.
It would be great help if you will explain in detail.

danguba
8 Jan 2011, 10:03 AM
Hi kashinath.
U don't actually have to click browse button at all. Instead U just type absolute path to file in regular upload field that is hidden behind ExtJs upload field. If U need details Ill have to check them with my Selenium test team on Monday because this was like 10 months ago and I only help them to locate the field. I hope Monday is not too late 4 U

danguba
10 Jan 2011, 5:42 AM
Hi kashinath,
I talked to Selenium team and here are the results.
Since we always have only one upload field they R using these two locators when they need to find field
css locator css=input[name=file]
xpath locator //input[@name='file']

Here is a firebug screenshot that can help U better understand the problem

24180

So selected input field is the hidden one U need. Just type in absolute address to file in it.
Input field above it is ExtJs input field and the table below is browse button.
I hope this makes it easier to understand

ethan.thomason
3 May 2011, 7:43 AM
Thanks danguba, I used XPather to track down my input id, which was:

/input[@id='ext-comp-1043']

then I added the following command:

Command: type
Target: //input[contains(@id, 'comp')]
Value: C:\\Users\\path\\test.txt

Ext JS is proving somewhat complicated to test with Selenium, but I've managed to come up with some workarounds.

danguba
3 May 2011, 8:13 AM
I just hope Sencha team will decide to release VisualQA for public so we won't have to use selenium workarounds anymore

ethan.thomason
3 May 2011, 8:18 AM
But then my past week's worth of work has been wasted!

danguba
3 May 2011, 10:43 AM
ROFL

testqa
30 Sep 2011, 9:09 AM
I do have same problem but still i am unable to find the solution.
Do i need to type on hidden input field or ExtJs input field before click on submit?

Can you please give me the exact step to work it out.

Thank you in advance.


Hi kashinath,
I talked to Selenium team and here are the results.
Since we always have only one upload field they R using these two locators when they need to find field
css locator css=input[name=file]
xpath locator //input[@name='file']

Here is a firebug screenshot that can help U better understand the problem

24180

So selected input field is the hidden one U need. Just type in absolute address to file in it.
Input field above it is ExtJs input field and the table below is browse button.
I hope this makes it easier to understand

danguba
30 Sep 2011, 9:13 AM
I do have same problem but still i am unable to find the solution.
Do i need to type on hidden input field or ExtJs input field before click on submit?

Can you please give me the exact step to work it out.

Thank you in advance.

Yes you need to type text before submit. It doesn't make any sense to do it after submit :D
So steps would be:
1. locate hidden field using selectors I mentioned earlier
2. type path to file in that field
3. do form submit

testqa
30 Sep 2011, 10:16 AM
I did thru css selector but it didn't type anything at all on hidden field location before click on submit, any idea why its not typing on hidden element?

(note-if i typed anything on ExtJs input field , i can see something has typed on this field.)

This is hidden field element:->
selenium.type("css=div[class='x-form-field-wrap x-form-file-wrap'] input[name='surveyFile']","C:\\file.txt");

thank you so much for your time.

danguba
30 Sep 2011, 12:02 PM
Sorry mate but I can't help you more before Monday. I need to consult with my QA team. Only two things are crossing my mind. We are using Selenium IDE for our tests and it looks like you are using Selenium RC. Maybe that is what is making the difference The other thing is Ext version. We R still on 3.2.1

mdmahboobali
22 Nov 2011, 3:04 AM
Hi all,

I have seen your post but unable to understand I mean I have used the method describe by Kashinath but still unable to get a break through , may be Iam doing something wrong,the main problem is I dont know anything abt selenium I have just installed it and trying to use it .... would appreciate any help.

Note: I am attaching copy of Firebug

amitgoyal
12 Jun 2013, 2:15 AM
you will definitely have type="file" component in your source of the page. like the example given below.

<input id="userFile-fileInputEl" class="x-form-file-input" type="file" size="1" name="userFile">

now, find the element using findElement() and then use sendKeys(). this should solve your problem.

i.e.
w.findElement(By.id("userFile-fileInputEl")).sendKeys("C:\\bizpulse.txt");

dabpr01
9 May 2014, 3:27 PM
awesome...the solution mentioned works perfectly...! thanks for sharing.
We also have ext based UI, and its real challenge to make web driver work, but its fun...

gajeshwar
2 Jun 2016, 1:51 AM
Can you please provide workaround you did. It will be very helpful for me.

Thanks in advance.