简体   繁体   English

Selenium C# 点击边上的“保存”

[英]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.我看过很多关于如何在 Edge 中的“另存为”window 上单击“Enter”的帖子,但似乎都没有用。 I am trying to download a file on my local machine but it seems that the ctrl + s works but enter doesn't.我正在尝试在我的本地计算机上下载一个文件,但似乎 ctrl + s 有效但 enter 无效。 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]);问题是当我要下载的发票生成时它会自动打开并聚焦新选项卡所以我不确定我是否需要 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.它单击控件的第一部分有效,但第二部分它应该有效,当“另存为”window 出现时将文件重命名为“test.pdf”,然后单击“返回”不起作用。 The "Save as" window appears but the test passes and the browser closes while the "Save as" window stays open. “另存为”window 出现,但测试通过并且浏览器关闭,而“另存为”window 保持打开状态。

I have also tried AutoIt and it same exact thing happens.我也尝试过 AutoIt 并且发生了同样的事情。

I have tried multiple ways but in the end I just stuck with disabling it asking for a download in pdf's.我尝试了多种方法,但最后我只是坚持禁用它,要求以 pdf 格式下载。 Edge sadly looks to be really limited compared to Chrome.遗憾的是,与 Chrome 相比,Edge 看起来真的很有限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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