5

I am using the EdgeDriver for running automation tests on my browser (Edge 38.14393.0.0). My tests are in C#, so I am using the .NET driver:

using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Edge;
    
var options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Normal;
    
RemoteWebDriver driver = return new EdgeDriver(Environment.CurrentDirectory, options, TimeSpan.FromSeconds(60));

driver.SetDocumentSize(new Size(800, 600)); // HERE!

The error

This code is the one I run at the beginning of the test. And it fails at the last line with:

Class Initialization method Web.TestSuite.UIRendering.RenderingTestSuiteEdge.TestClassInitialize threw exception. System.InvalidOperationException: System.InvalidOperationException: A window size operation failed because the window is not currently available.

With this stack trace:

OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs: line 1126
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs: line 920
OpenQA.Selenium.Remote.RemoteWindow.set_Size(Size value) in ...

FYI Be aware that I have other tests running on Chrome and IE11 using their respective drivers. When I call SetDocumentSize on those, I get no errors.

Open issues

I could find some open issues related to this problem:

Questions

So, these are my questions:

  • Has anybody succeeded in setting the window size in Edge?
  • Is this problem I am hitting a known issue? If so, is it fixed? The referenced issues (which look similar) are still open and no status provided.
  • Is there any workaround?

3 Answers 3

2

Try one of those for C#:

driver.Manage().Window.Size = new Size(1920, 1080);
driver.Manage().Window.Maximize();

Although I encounter that error for different reason (like the one here -> https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10319887/).

Now I kill all process of the driver & edge before each test so hopefully it will be resolved like that:

try
{
     foreach (var process in Process.GetProcessesByName("MicrosoftWebDriver"))
     {
           process.Kill();
     }

     foreach (var process in Process.GetProcessesByName("MicrosoftEdge"))
     {
           process.Kill();
     }
}
catch (Exception)
{
}

Also if you run them on remote machine via RDP for example it will make the same error when you close the RDP. This is the current workaround that I found for it:

Create a batch file with this code:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
  %windir%\System32\tscon.exe %%s /dest:console
)

Create a desktop shortcut to this file. To do this, right-click the batch
file and select Send to | Desktop (create shortcut).

In the shortcut properties, click Advanced and select Run as administrator.

Now, when you need to disconnect from Remote Desktop, double-click this shortcut on the remote computer (in the Remote Desktop window).

Thanks to https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/keeping-computer-unlocked.html for the script.

1

This works for me:

driver.manage().window().setSize(new Dimension(1250, 720));
1
  • Ahh. Yes, sorry, that is for Java. Mar 7, 2017 at 14:58
0

You can set window size for Microsoft Edge as shown below. *-window-size and window-size also work:

EdgeOptions options = new EdgeOptions();
options.AddArguments("--window-size=1024,768");
EdgeDriver driver = new EdgeDriver(options);

And, you can also set window size for Microsoft Edge with the code below according to the doc:

EdgeDriver driver = new EdgeDriver();
driver.Manage().Window.Size = new Size(1024, 768);

*My answer explains it more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.