I got a text box in a website and I wish to add an image over there using selenium in python language! I have seen a stackoverflow issue where the user had solved this problem in java lang !
Referrence : How to insert picture through selenium webdriver? !
(the textbox supports images as I am able to manually paste a copied image and there is also a button to upload images)
I have tried using element.sendkeys("image location path") as shown for java programme and it seems to be not working!
element.send_keys("assets/moon.jpg")
CodePudding user response:
According to the top answer found here:
How to upload file using Selenium WebDriver in Java
and here:
https://www.browserstack.com/guide/file-upload-in-selenium
You should include the absolute path to the file you would like to upload.
element.send_keys("full file path here")
From there you should be able to use:
driver.find_element_by_name("upload-button").click()
The idea is to send the file path and the click on the upload button.
CodePudding user response:
from io import BytesIO
import win32clipboard
from PIL import Image
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
filepath = 'a.jpg'
image = Image.open(filepath)
I have used this instead as I was required to finish that code urgently !
and have used
element.send_keys(Keys.CONTROL "V")