Upload file Without clicking upload button

Ask general questions here.
pansujit
Posts: 18
Joined: Mon Apr 18, 2016 2:56 pm

Upload file Without clicking upload button

Post by pansujit » Thu Jan 19, 2017 12:20 pm

Hello,
I am new to Ranorex and I would like to know , if it possible to upload file without clicking the upload file button. In selenuim, sendkeys(pathToFile) does the same work. But I don't know how to implement in Ranorex.

The web elements in the webpage as give

<input type="file" multiple="" name="files[]"/>

In seleium I did the the following and it works
driver.findElement(by.Xpath(".//input[@name='files[]']")).sendkeys(pathoffile);
but what is equivalent in Ranorex.

I am waiting for your suggestions.
Thanking you

Sujit pandey

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Upload file Without clicking upload button

Post by odklizec » Fri Jan 20, 2017 9:20 am

Hi,

I believe you can use SetValue action to achieve this? Just add SetValue action and select TagValue attribute for given repo element. Then add the path to file as a value (variable). Hope this helps?

BTW, I don't think it's a good idea to avoid using browser dialog and directly set the file to input tag. You see, it's not entirely "user-like" approach? And Ranorex tests are about mimicking user inputs ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

pansujit
Posts: 18
Joined: Mon Apr 18, 2016 2:56 pm

Re: Upload file Without clicking upload button

Post by pansujit » Fri Jan 20, 2017 11:12 am

Yes you are right. It mimics the user action. I have problem because my uploadfile button has problem for the moment but atleast works for the uploading file. SO I would like to input file name without opening the upload file.
The weblocator is decribed as follows
<input class="" type="file" multiple="" name="files[]"/>
and my RX path is:
/dom//form[#'corpusManagerFileUpload']/div[2]//input[@name='files[]'] which named as AbcPath

I have tries setvalue and tag value method but have no luck yet.
I tried
AbcPath.Element.SetAttributeValue("input",path); -- not worked
AbcPath.Element.SetAttributeValue("type",path);-- not worked
AbcPath.Element.SetAttributeValue("name",path);--not worked
AbcPath.Element.SetAttributeValue("files[]",path);--not worked

I don't know how to set this.
Thanking you

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Upload file Without clicking upload button

Post by odklizec » Fri Jan 20, 2017 12:12 pm

Hi,

As mentioned, you need to use TagValue (Value might work as well) attribute. So the code should look like this:

Code: Select all

AbcPath.Element.SetAttributeValue("TagValue",path);
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

pansujit
Posts: 18
Joined: Mon Apr 18, 2016 2:56 pm

Re: Upload file Without clicking upload button

Post by pansujit » Mon Jan 30, 2017 1:01 pm

Thanks for your reply. I will do accordingly and let updated.

sujit pandey

digitalcoyote
Posts: 1
Joined: Mon May 01, 2017 4:21 pm

Re: Upload file Without clicking upload button

Post by digitalcoyote » Mon May 01, 2017 4:32 pm

odklizec wrote: BTW, I don't think it's a good idea to avoid using browser dialog and directly set the file to input tag. You see, it's not entirely "user-like" approach? And Ranorex tests are about mimicking user inputs ;)
I disagree with this pretty strongly. Unless you are testing the Operating System or the Browser itself, testing how the browser handles standard inputs is a brittle way to handle things if you are concerned with how your website is handling the file.

That being said, I would love to know if anyone has this figured out. In Selenium we would just send keys to the input with the file name to get around OS implementations, but this seems to not work in Ranorex and we get an error when attempting to set the tagValue saying that it cannot be set programmatically. I'd be fine with automating the OS/browsers file dialog if it was consistent and worked on our test machines, but on Win 10 it seems to be reopening the file browser after we click "Open" with Ranorex.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Upload file Without clicking upload button

Post by Support Team » Thu May 04, 2017 3:26 pm

Hello digitalcoyote,

due to security reasons it should actually not be possible to set the file name programmatically.
Here is a post on Stackoverflow regarding this topic.
http://stackoverflow.com/questions/1017 ... 37#1017237

For other html tag types like text, changing the value is possible with the way odklizec described.
Another way is setting the value via JavaScript by using the ExecuteScript() method in Ranorex.
mydoc.ExecuteScript("document.getElementById('myText').value = 'Johnny Bravo';");
Best regards,
Bernhard
.
Image

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Upload file Without clicking upload button

Post by krstcs » Thu May 04, 2017 4:35 pm

digitalcoyote wrote: I disagree with this pretty strongly. Unless you are testing the Operating System or the Browser itself, testing how the browser handles standard inputs is a brittle way to handle things if you are concerned with how your website is handling the file.
I'm curious what part specifically you disagree with? His statement is completely correct as far as Ranorex and functional testing is concerned. Functional testing REQUIRES testing how a user would use the system.

Ranorex is a Function UI Automation tool. It is designed specifically to test what a USER would do using the provided INTERFACE, not back-end script injection. (If your users are injecting scripts, then you have other issues...)
Shortcuts usually aren't...