Selenium WebDriver: Upload multiple files

前端 未结 3 423
无人共我
无人共我 2020-12-05 11:52

My test need to upload test files in different browsers (I use WebDriver + Java). For a single file upload, everything works fine. I just send the

相关标签:
3条回答
  • 2020-12-05 12:05

    I also get chance to upload multiple files via Selenium.

    Finally get the solution using AutoIT.

    You can pass file path at run time.

    ControlFocus(“File Upload”,””,”Edit1″)
    ControlSetText(“File Upload”,””,”Edit1″,$CmdLine[1])
    ControlClick(“File Upload”,””,”Button1″)
    
    
    Runtime.getRuntime().exec("C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe"+" "+"C:\\Users\\Mukesh_50\\Downloads\\VerifyTitle.java");
    

    If finding any issue then check complete article with video.

    0 讨论(0)
  • 2020-12-05 12:29

    The solution for me (selenium in python) was to just repeat send_keys for each image path before uploading.

    Example for two files:

    driver.find_element_by_name("filename").send_keys(file_path_1)
    driver.find_element_by_name("filename").send_keys(file_path_2)
    driver.find_elements_by_xpath("//*[contains(text(), 'Upload')]")[0].send_keys(Keys.RETURN)
    
    0 讨论(0)
  • 2020-12-05 12:31

    As far as I know, selenium still does not support multiple file upload (see issue on google code).

    There is at least one workaround: apparently create a form that contains as many input fields as you need (see another stackoverflow question). Not the best solution, as it (probably) requires altering your code for selenium to work.

    However, as you have found out (thanks for this!), it does seem possible to trigger multiple file uploads in chrome and (although I did not test it) IE as well.

    I just confirmed that the chrome "\n" trick works both locally and on Browserstack (I used the default images they provide), which, considering the state of things, is good enough for me.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题