javascript - 如何使用 WebdriverIO 设置下载 .dmg 文件的首选项?

标签 javascript webdriver-io

我想使用 webdriverIO 下载一个 .dmg 文件,单击链接后会弹出文件下载弹出窗口,这是一个 .dmg 文件。如何处理询问“保存”或“取消”的弹出窗口?

最佳答案

如果问题是保存弹出窗口,那么您可以通过为浏览器设置默认下载位置来避免弹出窗口。

对于 Chrome :

wdio.conf.js 文件中,在 capabilities 中添加以下内容:

Note: Before adding make sure you have defined downloadDir with the default path where the file needs to be saved.

capabilities: [{
    browserName: 'chrome',
    // this overrides the default chrome download directory with our temporary one
    goog:chromeOptions: {
      prefs: {
        'download.default_directory': downloadDir
      }
    }
  }]

此代码将设置默认下载目录,您将不会再看到弹出窗口。

更多信息:https://blog.kevinlamping.com/downloading-files-using-webdriverio/

关于javascript - 如何使用 WebdriverIO 设置下载 .dmg 文件的首选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56001733/

相关文章:

javascript - 随着时间的推移,Allure 报告不断增长并需要更长的时间来生成

Javascript:使用元组作为字典键

javascript - 如何以编程方式生成代码以在 jsfiddle.net 中显示?

node.js - WebdriverIO : Dot ('.' ) is not recognized as an internal, 或外部命令

node.js - 如何使用 Node JS/Webdriver.io/Chimp 打印为 PDF?

javascript - 元素命令无法完成,因为该元素在页面上不可见

javascript - 未捕获的类型错误 : undefined for Bootstrap Modal

javascript - 如何返回一个对象与两个 Mongoose 模型相结合

javascript - 在 PHP 中单击时使引用切换为粗体

javascript - 无法遍历多个选择器($$,findElements)webdriver.io