Cannot upload file to D365 in headless mode Selenium C#

Viewed 33

I have a set of Dynamics 365 automated tests which run fine whilst the browser window is open on the screen, but when I run the tests in headless mode, all of them fail when trying to upload a document.

This is my current code for uploading the file:

PaperClipButton().Click();  // this clicks the paperclip icon to open the file upload window
Driver.SwitchTo().ActiveElement();
SendKeys.SendWait(@$"{rootDirectory}\MyFile.pdf");
SendKeys.SendWait(@"{Enter}");

When running in headless mode it inputs the string that is supposed to go into the file upload window inside the Visual Studio window when I'm debugging the test and not in the browser where it's supposed to go.

I've checked the failure screenshot and it doesn't open the file upload window at all and fails on the step where it checks the file has been uploaded.

Also tried removing the line for SwitchTo().ActiveElement() but get the same result

Has anyone had similar issues with D365 automation?

Thanks in advance

0 Answers
Related