简体   繁体   English

通过 selenium webdriver 下载 pdf 文件然后需要发送到 gmail

[英]Download pdf file through selenium webdriver and then need to send on gmail

I have a test case where I need to download a user report pdf that needs to download through selenium web driver and then send it to email with attachment downloaded pdf to particular user I have a test case where I need to download a user report pdf that needs to download through selenium web driver and then send it to email with attachment downloaded pdf to particular user

Is it possible through selenium webdriver?是否可以通过 selenium webdriver? if yes, then please suggest me how can I achieve it.如果是,那么请建议我如何实现它。

Thanks in advance!提前致谢!

As per the logic mention by you, let's discuss all the solutions pointwise.根据您提到的逻辑,让我们逐点讨论所有解决方案。

  1. On my web page there is a button download where I can download the user report pdf.在我的 web 页面上有一个按钮下载,我可以在其中下载用户报告 pdf。

  2. By clicking the download button it's downloaded pdf in the local system of windows.通过单击下载按钮,它在 windows 的本地系统中下载了 pdf。

Answer: Try to download it in a specific folder by setting your default directory path.答:尝试通过设置默认目录路径将其下载到特定文件夹中。

    Map<String, Object> prefs = new HashMap<>();
    prefs.put("download.prompt_for_download", false);
    String downloadFilepath = USER_DIRECTORY+"/downloads/";
    prefs.put("download.default_directory", new File(downloadFilepath) );
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    WebDriver driver = new ChromeDriver(options);
  1. Use JavaMail API - Sending Email With Attachment to send your pdf.使用JavaMail API - 发送带有附件的 Email 发送您的 pdf。 Ref: https://www.tutorialspoint.com/javamail_api/javamail_api_send_email_with_attachment.htm参考: https://www.tutorialspoint.com/javamail_api/javamail_api_send_email_with_attachment.htm

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

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