'python selenium upload images to an element?

How do I upload images to an element?

enter code here

<input type="file" class="inline_upload" onchange="WallPosting.onFeedUploadInputChange(this, event, '/wall?act=add&amp;from=feed')" accept="image/jpeg,image/png,image/gif,image/heic,image/heif,image/webp" data-upload-url="https://pu.vk.com/c857212/ss2163/upload.php?act=album_photo&amp;aid=-14&amp;gid=0&amp;_fwadd=new_wall709213741&amp;mid=709213741&amp;server=857212&amp;_origin=https%3A%2F%2Fm.vk.com&amp;_sig=82656bb973534e61b945f0a9c7ce168f" data-done-url="/photos.php?act=done_upload" data-max-attaches="10" multiple="multiple" tabindex="0" aria-label="รูปจากอุปกรณ์">


Solution 1:[1]

As I can see from the HTML, you've got an input box that has a type and value is file.

So, you can use the //input[@type='file'] XPath to upload a file.

Code:

driver.find_element(By.XPATH, "//input[@type='file']").send_keys('full path of the file that you want to upload')

You can also use explicit wait like below:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='file']"))).send_keys('full path of the file that you want to upload')

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cruisepandey