Webdriver: File Upload

后端 未结 7 1234
日久生厌
日久生厌 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:37

    I am in search of 3rd party libraries too,

    Unless there is no any other Window Then this works for me :

    in C# add reference for System.Windows.Forms

    using System.Windows.Forms;
    
    string url = "http://nervgh.github.io/pages/angular-file-upload/examples/image-preview/";
    string path = @"C:\Users\File_Path";
    IWebDriver d = new ChromeDriver();
    d.Navigate().GoToUrl(url);
    d.FindElement(By.XPath("//input[@type='file']")).Click();
    hread.Sleep(5000);
    System.Windows.Forms.SendKeys.SendWait(path);
    System.Windows.Forms.SendKeys.SendWait(@"{Enter}");
    

提交回复
热议问题