[英]Selenium download button indicates a zip file download by browser in Java
我在网页中有一个没有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
我正在寻找类似的东西,我可以在我的项目中处理下载的文件。 (在reportsFolder路径中)不幸的是,此解决方案不起作用,因为ExtendedElement(findExtendedElement(“ span”,“ class”,“ download_0”)没有“ a href”标签)
谢谢
此xpath: "//span[contains(@class,'download_o')]"
应该有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.