Save/copy To Clipboard Image From Page By Chrome Console
Solution 1:
I have explored few things in chrome dev tools
https://homeguides.sfgate.com/stop-air-flow-ceiling-air-diffuser-28867.html - This is the website I am using it for reference.
- In Chrome console try the following command
imageurl= document.getElementsByTagName('img')[0].currentSrc;
copy (imageurl);
Note: Here you can change the img [1] array if you want to get different images
Then if you press ctrl + v in your keyboard you could see the image url with https. Please see the above screenshot.
You can perform the ctrl+ v on your new tab to get the image loaded.
orYou can try the following method.
- Right click the image and click inspect element
- You could see some image url. Copy that URL
- Open new Tab and paste the URL
- If you right click on it you can see "Save Images" option.
Hope it will help you in someway.
Solution 2:
As you mentioned you are using Selenium, here's how to save an image with Selenium:
You need to get the image's URL, load it (using ImageIO
in this example) and save it. For example, in Java you would do something like this:
try {
driver = newChromeDriver();
driver.get("http://...");
WebElementimg= driver.findElement(By.cssSelector("#selector"));
BufferedImagebuffer= ImageIO.read(newURL(img.getAttribute("src")));
ImageIO.write(buffer, "png", newFile("image.png"));
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.close();
}
If you want to copy it directly, your class needs to implement java.awt.datatransfer.ClipboardOwner
and then you would do something like this:
try {
driver = newChromeDriver();
driver.get("http://...");
WebElementimg= driver.findElement(By.cssSelector("#selector"));
TransferableImagetransferable=newTransferableImage(ImageIO.read(newURL(img.getAttribute("src"))));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, this );
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.close();
}
Regarding your other questions, here's how to take a screenshot using Chrome DevTools:
There are 3 Capture... commands in Chrome DevTools. Just follow these steps to get to them:
Open DevTools.
Go to the Elements tab and click on the element you want to take the screenshot of.
Press Cmd + P on Mac or Ctrl + P on Windows.
Type
> screen
. You will get 3 relevant suggestions:Mobile
Capture full size screenshot: Captures the whole page, including the non-visible (out of viewport) area.Mobile
Capture node screenshot: Captures a single node, in this case, the element you clicked in the second step.Mobile
Capture screenshot: Captures the visible area of the page (viewport).
Click on any of them and the screenshot will download automatically.
However, keep in mind this feature doesn't always work fine, especially the Capture node screenshot one, so it might be better to capture the visible area of the page and crop the afterwards.
Solution 3:
there is built in feature to do many common things ;)
#noLibrary #builtInFeature
Command menu
- CTRL + SHIFT + P
- https://umaar.com/dev-tips/98-command-menu/
Screenshot tutorial
https://umaar.com/dev-tips/151-screenshot-capture/
Post a Comment for "Save/copy To Clipboard Image From Page By Chrome Console"