>我在网页中有一个没有href链接的下载按钮。 我用findExtendedelement找到它并单击它。 单击硬盘驱动器上的zip文件后下载(我不知道在哪里,应该没关系( 我想捕获这个下载的zip并将其放在我的项目中,例如构建/报告/测试/临时文件夹。
硒可能吗?
更新
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" 标签(
谢谢
这个 xpath:"//span[contains(@class,'download_o')]"
应该工作