1

I am using Windows.Forms.SendKeys.SendWait to interact with the native windows dialog when uploading an image.

I click the upload button using webdriver, then go:

SendKeys.SendWait("^A"); //Highlight content so it can be overwritten
SendKeys.SendWait(path);
SendKeys.SendWait(@"{Enter}");

Works great when I run it locally on my PC, however, the test won't run on the TeamCity agent (I have many other tests that run OK). It fails as it seems that native dialog never appears or if it does, it can't interact with it.

Not sure what's happening as this whole test agent process runs in the background and I can't see what it's doing - I can take screenshots using webdriver but it won't capture native dialogs anyway.

I tried to configure the team city test agent windows service (change Log On settings to allow interacting with desktop) but this did not work. Seems it just isn't able to interact with it... any ideas on how to make this work?

Xena
  • 378
  • 2
  • 12

1 Answers1

1

In order to upload a file with Selenium, you should use Webdriver's SendKeys directly to the input element that requires the path (Not Forms.SendKeys). See this example.

Note: You'll need to avoid clicking the button that opens the dialog.

Community
  • 1
  • 1
Moshisho
  • 2,781
  • 1
  • 23
  • 39
  • thanks for the answer & the link to the example. Seems like this is the only way to make this work. *However* I would argue that this is not really a good UI test. The user would not interact with the page like this. So for example, the upload button could be broken and the user might not be able to upload photos, but the test would still pass. – Xena Dec 06 '16 at 21:54
  • Well you have a point, but your alternative is to always have a user logged on and screen unlocked, and change your team city agent to run as a process instead of a service... – Moshisho Dec 06 '16 at 22:38
  • This is true - not worth the effort. In my test, I first check that the upload button is at least visible & enabled *then* proceed with your solution. It works on teamcity! Thanks. – Xena Dec 06 '16 at 23:07