java - Selenium 没有通过它的 xPath 找到元素
问题描述
试图通过其 xPath 从 Facebook 上传一些图像,没有幸运,还有其他方法吗?
爪哇:
var xPathContato = "//*[@id=\"mount_0_0_lv\"]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div/div[3]";
WebElement wb = webDriver.findElement(By.xpath(xPathContato));
String image = wb.getAttribute("src");
URL imageURL = new URL(image );
BufferedImage saveImage = ImageIO.read(imageURL);
ImageIO.write(saveImage, "png", new File("facebook-img"));
错误:
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="mount_0_0_lv"]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div/div[3]"}
解决方案
我认为你在混淆一些东西。该元素并没有真正退出您正在上传到 selenium 的页面中,否则它会毫无问题地显示出来,但该元素基本上只存在于浏览器的开发人员工具栏中。
推荐阅读
- python - Pandas read_hdf() 在有效 where 条件下返回“无效变量引用”
- bash - 如何在 bash 命令中转义 $
- java - 写入 jar 文件中的 xml 文件
- python - _tkinter.TclError:预期的整数,但得到“衬线”
- sql-server - Filepicker VBA选择文件并存储文件名不起作用
- android - 单击任何按钮时应用程序停止工作,错误说它找不到方法
- java - 在 intelij 中通过数据库模式映射实体对象会生成错误的注释和关系
- html - 切换到移动设备时,HTML 正文未占用全宽
- css - 安装 Bootstrap(在 Angular 上,但有错误)
- javascript - 单击子元素时反应获取父元素的状态/数据