Webdriver: File Upload

后端 未结 7 1097
日久生厌
日久生厌 2020-11-27 18:16

Is there a way to interact with a File Upload box in webdriver? The form field where the path gets put in is read only so I can\'t write to that.

相关标签:
7条回答
  • 2020-11-27 18:53

    For C#, SendKeys() works but you have to use \ in your file path instead of /

    For example, the follow works :

    string filePath = @"drive:\path\filename.filextension";
    driver.FindElement(By.Id("fileInput")).SendKeys(filePath);
    

    But the following doesn't work :

    string filePath = "drive:/path/filename.filextension";
    driver.FindElement(By.Id("fileInput")).SendKeys(filePath);
    
    0 讨论(0)
提交回复
热议问题