0

我在网页中有一个没有 href 链接的下载按钮。我用 findExtendedelement 找到它并单击它。单击硬盘驱动器上的 zip 文件下载后(我不知道在哪里,这不重要)我想抓住这个下载的 zip 并将其放入我的项目中,例如 build/reports/tests/temp 文件夹.

硒可以吗?

更新

HTML 看起来: https ://i.stack.imgur.com/YnhlH.jpg

我试过这段代码:

@Test
public void userCanDownloadFile() throws FileNotFoundException, IOException
{
 // Folder to store downloads and screenshots to.
 reportsFolder = "./src/test/profiles/chrome/downloads/";

 open("http://chromedriver.storage.googleapis.com/index.html?path=2.16/");

 // Download files
 $("a[href='/2.16/chromedriver_win32.zip']").download();
    $(By.xpath(".//a[@href='/2.16/chromedriver_mac32.zip']")).download();

    // Count files in folder, assert 2
    int downloadsCount = new File(reportsFolder+"2.16").listFiles().length;
    assertEquals("Should be 2 files but founded " + downloadsCount,  
          downloadsCount, 2); 

    // Clean after test
    FileUtils.deleteDirectory(new File(reportsFolder+"2.16"));
}

结果:java.lang.IllegalArgumentException:该元素没有 href 属性:

代码来自: http ://selenide-recipes.blogspot.com/2015/08/how-to-download-file-with-selenide.html

我正在寻找类似的东西,我可以在我的项目中处理下载的文件。(在报告文件夹路径中)不幸的是,此解决方案不起作用,因为 ExtendedElement (findExtendedElement("span", "class", "download_0") 没有“a href”标签)

谢谢

4

1 回答 1

0

这个 xpath:"//span[contains(@class,'download_o')]"应该可以工作

于 2018-06-05T06:38:48.227 回答