我在网页上有一个没有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"标签)
由于
答案 0 :(得分:0)
此xpath:"//span[contains(@class,'download_o')]"
应该可以正常工作