1

How do I go about inserting or copy/pasting an inline image with Selenium?

Currently I have the script taking a screenshot of the target image with selenium and opening it with Pillow.

driver.get("https://www.google.com/")
time.sleep(3)
screenshot = driver.find_element_by_xpath("//*[@id=\"hplogo\"]").screenshot_as_png      
image = Image.open(io.BytesIO(screenshot))
Zazi
  • 11
  • 1

1 Answers1

0

Was able to solve the problem with code from this post.

image = Image.open(io.BytesIO(screenshot))
output = io.BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()

elem.send_keys(Keys.CONTROL + "v")
Zazi
  • 11
  • 1