【问题标题】:How to set the value of a html input file element in the html page of the web browser control?如何在 web 浏览器控件的 html 页面中设置 html 输入文件元素的值?
【发布时间】:2013-09-09 15:00:15
【问题描述】:

如何在网页浏览器控件的html页面中设置html输入文件元素的值?

例如:

对于html输入元素,

<input type="text" name="userName" maxlength="10" value="" id="Login_userName"> 

我们在 C# 中有如下代码来设置输入类型文本的值:

//Assigning value to a textbox control
wbEfile.Document.GetElementById("Login_userName").SetAttribute("value", access.pannumber.ToString());

现在,我的问题是如何为类型文件(如下所示)的 html 输入元素设置值?

<input type="file" name="uploadFile" value="" id="UploadReturn_uploadFile"> 

【问题讨论】:

    标签: winforms c#-4.0 file-upload webbrowser-control


    【解决方案1】:

    你不能这样做。输入 type="file" 具有安全性,因此您不能直接从 JavaScript 访问文件。

    【讨论】:

      【解决方案2】:
       HtmlElement ele = webBrowser1.Document.GetElementById("Login_userName");
       if (ele != null)
          ele.InnerText = access.pannumber.ToString();
      

      【讨论】:

        【解决方案3】:

        为将来的参考提供较晚的答案。如果目标是为 &lt;input type="file"/&gt; 元素提供文件名以用于 UI 测试自动化目的,here's how 可以做到。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-10-27
          • 2022-01-03
          相关资源
          最近更新 更多