Search code examples
pythonseleniumselenium-webdriverxpathwebdriverwait

How upload file with selenium


I trying to upload video file with selenium, it doesn't work

my code:

a = wait.until(EC.element_to_be_clickable((By.TAG_NAME, 'input'))) browser.execute_script("arguments[0].style.visibility = 'visible'", a) a.send_keys("C:/Users/NIKITA/Desktop/vk_clips/testvid.mp4")

enter image description here

This script works but doesn't load the file and doesn't throw an error. I tried searching for the element using XPath, it causes a timeout exception.


Solution

  • The web element actually accepting the uploaded file is matching this XPath: "//input[@type='file']". This element is not visible. You can see yourself on picture you shared visibility: hidden.
    Again, this is not an element you clicking when uploading file manually as a user via the GUI.
    So, to upload file to it you can not wait for it to become visible or clickable.
    Just wait for this element presence.
    Your code can be something like the following:

    wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@type='file']"))).send_keys("C:/Users/NIKITA/Desktop/vk_clips/testvid.mp4")