简体   繁体   English

Selenium 没有通过它的 xPath 找到元素

[英]Selenium does not find element by it's xPath

Trying to upload some image from Facebook by its xPath, without lucky, any other way to do it?尝试通过其 xPath 从 Facebook 上传一些图像,但运气不佳,还有其他方法吗?

在此处输入图片说明

Java:爪哇:

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"));

Error:错误:

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]"}

I think you are mixing something up.我认为你在混淆一些东西。 The elemnt doesn't really exit in the page you are uploading into selenium, otherwise it would be shown without any problems, but the element exist basically only in your developer toolbar of your browser.在您上传到 selenium 的页面中,元素并没有真正退出,否则它会毫无问题地显示出来,但该元素基本上只存在于浏览器的开发人员工具栏中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM