Web浏览器和文件输入控件 [英] Webbrowser and file input controls

查看:104
本文介绍了Web浏览器和文件输入控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个自动化流程来模仿用户在本地运行的网站上所做的事情,我们无法访问该网站或其他任何内容来创建自动流程。

I am trying to write an automated process to mimic what a user would be doing on a locally run website for which we don't have access to source or anything else to create an automated process.

我已经到了需要通过INPUT type ='file'html控件选择要导入的文件的位置,我被卡住了。我知道这里只涉及设置我需要处理的文件的输入值所涉及的安全性。我可以
选择打开一个文件对话框,但打开后我无法与它进行交互。 

I have gotten to the point of where a file to import needs to be selected through a INPUT type='file' html control and I am stuck. I know there is security involved here in terms of just setting the value of the input to the file I need to process. I can make the choose a file dialog open but I am unable to interact with it after it opens. 

这是我当前代码的一部分

This is my current code for the part of the routine


Dim btn As HtmlElement
      Dim a As HtmlElementCollection = WebBrowser2.Document.GetElementsByTagName("input")
      For Each aa As HtmlElement In a

        If aa.Name = "importfile" Then

          'btn = aa
          aa.SetAttribute("value", "c:\LBIimportrights.csv")
          aa.Focus()
          SendKeys.SendWait("c:\LBIimportrights.csv")

          Dim mi As System.Reflection.MethodInfo
          Dim o As Object
          'Timer2.Start()
          btn = WebBrowser2.Document.GetElementById("btnLoad")
          o = btn.DomElement
          mi = o.GetType().GetMethod("click")
          mi.Invoke(o, New Object(-1) {})

          'System.Threading.Thread.Sleep(3000)
          'My.Computer.Keyboard.SendKeys("c:\lbiimportrights.cvs", True)
          'My.Computer.Keyboard.SendKeys("{ENTER}")

        End If

      Next

推荐答案

您可以使用HtmlElement.Invoke ("点击")方法直接执行点击操作。

You can just use the HtmlElement.Invoke("Click") method to do the click operation directly.

或者调用"提交"按钮。 html中表单的操作提交值。

Or invoke the "submit" action for the Form in html to submit the value.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ce396a44-43a5-49e4-bbc9-432a3c01ca39/

 

祝福,


这篇关于Web浏览器和文件输入控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆