Adding C# code to handle file upload window

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 5
Joined: Thu May 27, 2010 8:03 am

Adding C# code to handle file upload window

Post by pandiyarajk » Thu Nov 17, 2016 1:49 pm

I am working in Ranorex Studio 6.0.1 and have recorded a web browser automation test for file upload. During the run, upload button was not clicked on first attempt. I am planning to write C# code to ensure whether it is clicked or not. If it was not clicked, I want to click the button again. But the .cs file for the recording is locked and I don't know how to handle this using user code.

I am new to user code actions. Please help me to add user code for the same.


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

Re: Adding C# code to handle file upload window

Post by odklizec » Fri Nov 18, 2016 8:34 am


I would recommend you to read this User Guide chapter about creating User Code actions: ... tions.html

Basically, you need to create new user code action at a place, where you want to solve your problem. Anyway, instead of creating a workaround for failed click, you should investigate the reason why the click fails ;)
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

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

Re: Adding C# code to handle file upload window

Post by krstcs » Fri Nov 18, 2016 3:01 pm

Yeah, I agree with Pavel. The issue here is that your click isn't working the way you expected it to. That won't change just because you move the action to user code.

It is most likely a timing issue. Try to add a Delay action right before the click and see if that fixes it. If it does, then we know for sure it's timing. You can then work on making the xpath better or adding a WaitForExist action in place of the Delay (try not to use too many delays in your tests as they are not 'smart' and just wait the given time, while WaitFor(Exist/NotExist) are smarter and better for long-term test maintenance).
Shortcuts usually aren't...