Page 1 of 1

Upload file Without clicking upload button

Posted: Thu Jan 19, 2017 12:20 pm
by pansujit
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

Re: Upload file Without clicking upload button

Posted: Fri Jan 20, 2017 9:20 am
by odklizec
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 ;)

Re: Upload file Without clicking upload button

Posted: Fri Jan 20, 2017 11:12 am
by pansujit
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

Re: Upload file Without clicking upload button

Posted: Fri Jan 20, 2017 12:12 pm
by odklizec
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);

Re: Upload file Without clicking upload button

Posted: Mon Jan 30, 2017 1:01 pm
by pansujit
Thanks for your reply. I will do accordingly and let updated.

sujit pandey

Re: Upload file Without clicking upload button

Posted: Mon May 01, 2017 4:32 pm
by digitalcoyote
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.

Re: Upload file Without clicking upload button

Posted: Thu May 04, 2017 3:26 pm
by Support Team
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

Re: Upload file Without clicking upload button

Posted: Thu May 04, 2017 4:35 pm
by krstcs
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...)