[Python] How to drag and drop file with Python Selenium?

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to check in my test (selenium / python) creating a new image on the site. I need to load a picture for it. How can I do this when I have the option to use the drop or file explorer field. As far as I know, I can not use the file explorer because there is no id or name. How to use the drag and drop method?

    I have this code but it does not work:

    element = driver.find_elements_by_id ("file_upload")
    element.send_keys ( "C: \\ Users \\ Desktop \\ Robert \\ Construct_ImminentCollision-C.jpg")
    target = driver.find_element_by_id ("add-new-pano")

    action_chains = ActionChains (driver)
    action_chains.drag_and_drop (element, target) .perform ()


    "add-new-pano" is the drop field id.

    Continue reading...

Compartilhe esta Página