Page 1 of 1

Upload file Without clicking upload button

Posted: Thu Jul 18, 2019 2:37 pm
by nobeatas
I read below issue. but i didn’t solve problem ‘ upload file without clicking in selenium ‘
https://www.ranorex.com/forum/filepath- ... 12533.html

The solution presented that using setvalue action and select tagvalue is not working my environment.

I tried setting to below element
<input class=“upload” type=“file” ></input >

Setting
Action:Set Value
Name: TagValue
Value: C:\Temp\test.jpg

Result is success, but not working upload file. Nothing happened in browser.
I think that can find target input.

I’m waiting for suggestion or another way.

Thank you for reading ugly english :oops:

Using Ranorex version : 8.3.1
Using browser: chrome ver 75.0.37
Sorry I cannot attach screenshot in my environment.

Re: Upload file Without clicking upload button

Posted: Fri Jul 19, 2019 12:11 pm
by odklizec
Hi,

Could you please upload a Ranorex snapshot (NOT screenshot) of the web page you are trying to automate? Also, do I understand it right that it must be a webdriver-based solution? Are you going to run your tests via webdriver integration?

Generally speaking, I think you must somehow merge these two codes together:
https://www.ranorex.com/forum/upload-fi ... 11782.html#
https://www.ranorex.com/forum/back-butt ... tml#p55275
Sadly, I'm not using webdriver so I can't tell you how to merge them exactly ;)

Another approach could be using javascript. Try this sample code:

Code: Select all

sing System.Linq;
using OpenQA.Selenium;
// uploadButton: repo element of upload button to click
// path: path to file you want to set in input 
public static void UploadFileWithWebdriver(RepoItemInfo uploadButton, string path)
{ 
    var webDriverEndpoint = Host.Current.TryGetAsWebDriverEndpoint();
    IWebDriver driver = webDriverEndpoint.WebDrivers.FirstOrDefault();    
    String script = "document.getElementsByClassName('upload').value='" + path + "';";
    ((IJavaScriptExecutor)driver).ExecuteScript(script);
    uploadButton.CreateAdapter<Ranorex.Unknown>(false).Click();
}