c# - 如何在 Selenium 中设置 Edge 的下载文件夹?
问题描述
我正在使用 Selenium 编写自动化测试。我想在 Edge 中设置下载目录,以便我可以下载文件作为测试的一部分。我可以在创建 EdgeDriver 时提供一个 EdgeOptions 对象,但我不知道在 EdgeOptions 上设置什么。
我知道相当于如何在 Chrome 中执行此操作
chromeOptions.AddUserProfilePreference("download.default_directory", @"C:\temp")
和火狐
firefoxOptions.SetPreference("browser.download.dir", @"C:\temp")
但是,我如何在 Edge 中做同样的事情?并让它在没有保存提示的情况下自动下载?
解决方案
正如@Prany 已经提到的,可能无法自动设置下载。如果我理解正确,当您单击下载按钮时,您想处理本机窗口对话。Selenium 不能与原生窗口交互,但你可以使用这个框架。示例代码如下所示:
// Press the A Key Down
KeyboardSimulator.KeyDown(Keys.A);
// Let the A Key back up
KeyboardSimulator.KeyUp(Keys.A);
// Press A down, and let up (same as two above)
KeyboardSimulator.KeyPress(Keys.A);
// Simulate (Ctrl + C) shortcut, which is copy for most applications
KeyboardSimulator.SimulateStandardShortcut(StandardShortcut.Copy);
// This does the same as above
KeyboardSimulator.KeyDown(Keys.Control);
KeyboardSimulator.KeyPress(Keys.C);
KeyboardSimulator.KeyUp(Keys.Control);
所以可以模拟Ctrl + V
键盘动作和Enter
动作。希望能帮助到你。
推荐阅读
- android - 执行 A/B 测试时何时为 Firebase 获取 RemoteConfig
- css - wordpress 古腾堡 alignwide 和 alignfull 问题
- java - Quartz 作业未通过 XMLSchedulingDataProcessorPlugin 启动
- angular - 重定向到 Angular 应用程序之外但在同一个域中的 URL
- python - wxPython FileDialog 防止某些文件被拾取
- angular4-forms - 在 Angular-4 中单击 AddMore 按钮验证模板驱动的表单
- javascript - 如何通过收音机和 Javascript 在 HTML 中使用更改位置
- ionic-framework - 在 ipcRenderer.on 事件处理程序中设置全局变量在电子上运行离子不起作用
- compiler-construction - ocaml编译器是使用编译器前端模块parse来解析源码还是使用ocamlyacc来解析源码?
- html-table - 原生 HTML 和 zk-if 的奇怪错误