【问题标题】:File download using Selenium ChromeDriver in Jenkins在 Jenkins 中使用 Selenium ChromeDriver 下载文件
【发布时间】:2018-11-10 09:27:50
【问题描述】:

我正在使用一段 Selenium 代码 (Java) 自动下载文件 (xlxs) 并通过电子邮件将其发送给收件人列表。

我已经使用 Maven 将它集成到 Jenkins 中,我进入了可以按下按钮下载文件的步骤,但是在工作区或服务器上的任何地方都找不到该文件。

我想获取文件以将其附加到电子邮件中,使用 Jenkins 并发送。

当我在本地执行此操作时,文件会自动下载到默认的“下载”文件夹中,但在服务器端却不一样。

关于此文件的下载位置或如何指定下载文件夹的任何建议。

谢谢。

【问题讨论】:

  • 用你的代码更新问题。
  • 代码做了需要做的事情(按下按钮触发文件下载),我没有看到这里添加代码的好处。我需要做的是能够将文件发送到某个文件夹,以便使用 Jenkins 将其附加到电子邮件中。
  • 您可能看不到添加代码的好处,但是回答问题的 SO 上的人会看到!将代码与您的问题一起提供有多种优势,例如:1. 它使我们免于提出您可能已经尝试过为每个人节省一些时间的建议,2. 它向我们表明您在提出问题之前已经完成了相当多的研究,并且最重要的是 3. 当您提供所有信息来解决问题时,您更有可能获得高质量的答案。我本可以试着回答你的问题,但我不得不写这篇评论

标签: selenium jenkins selenium-chromedriver


【解决方案1】:

注意:我使用的是 Firefox,所以我的代码有点不同。

您可以指定下载文件夹或使用现有的自定义浏览器配置文件

使用临时浏览器配置文件:

FirefoxProfile selenium_profile = new FirefoxProfile();
selenium_profile.setPreference("browser.download.folderList",2);    
selenium_profile.setPreference("browser.download.dir", "C:\\Users\\pburgr\\Desktop\\BP_usr_tmp\\");
selenium_profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
options.setProfile(selenium_profile);

使用现有配置文件:

@BeforeClass
public static void setUpClass() {
    FirefoxOptions options = new FirefoxOptions();
    ProfilesIni allProfiles = new ProfilesIni();         
    FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
    options.setProfile(selenium_profile);
    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
    driver = new FirefoxDriver(options);
    driver.manage().window().maximize();}

【讨论】:

    【解决方案2】:

    我发现文件放在这里:

    C:\Program Files (x86)\Google\Chrome\Application\used_version
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2018-09-30
      • 2018-02-09
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多