简体   繁体   中英

Selenium C# click "Save" on edge

I have seen a lot of posts about how to click "Enter" on the "Save as" window in Edge but none seem to be working. I am trying to download a file on my local machine but it seems that the ctrl + s works but enter doesn't. I am using the following:

using Framework.Core; 
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Threading;
using System.IO;
using System.Linq;
using OpenQA.Selenium.Interactions;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using SeleniumExtras.WaitHelpers;

The code that doesn't seem to be executing:

        driver.SwitchTo().Window(driver.WindowHandles[1]);
        Thread.Sleep(4000);          

        Actions savePDF = new Actions(driver);
        savePDF.KeyDown(Keys.Control)
           .SendKeys("s")
           .KeyUp(Keys.Control)
           .SendKeys("test.pdf")
           .SendKeys(Keys.Return)
           .Build()
           .Perform();

The thing is when the invoice I want to download generates it automatically opens and focuses the new tab so I am not sure if I even need the driver.SwitchTo().Window(driver.WindowHandles[1]);

The first part where it clicks control s works but the second part where it supposed to, when the "Save as" window appears rename the file to "test.pdf" then click "Return" doesn't work. The "Save as" window appears but the test passes and the browser closes while the "Save as" window stays open.

I have also tried AutoIt and it same exact thing happens.

I have tried multiple ways but in the end I just stuck with disabling it asking for a download in pdf's. Edge sadly looks to be really limited compared to Chrome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM