我正在尝试写代码来检查selenium和chrome驱动程序是否完成了下载。我的想法是
1.转到下载页面(“chrome://downloads/”)
2.检查url以确保我们已从该站点下载了文件(定位http://xxxxxxxx)
3.检查下载状态(如果我发现"show in folder",表示下载成功。如果不是,则下载失败)
当我试图定位url时,我在step2中卡住了。我使用开发人员工具,将光标移动到url来定位元素,然后右键单击并复制xpath。xpath如下所示
//*[@id="file-link"]
然后,我尝试在开发人员工具中单击ctrl+F并再次粘贴xpath。我找不到该元素。为什么?已检查是否没有框架。
发布于 2018-12-03 12:15:41
它会隐藏DOM,并需要使用CSS选择器选择/deep/
downloads-manager/deep/downloads-item/deep/a[id="file-link"]
发布于 2018-12-03 18:24:04
另一种方法是使用File类为相同的应用程序编写一个小型Java实用程序。如下所示:
File f = new File("C:\\Users\\username\\Downloads\\Users_" + fielName+ ".xls");
Assert.assertTrue(f.exists());
https://stackoverflow.com/questions/53587283
复制相似问题