简体   繁体   中英

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?

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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