locked
Webbrowser and file input controls RRS feed

  • Question

  • 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.

    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
    
    I suspect this is all still part of the security but is there a way to do this? I can complete this silly process if I can get the dialog to type the path:\file into the box and then hit enter.

    Tuesday, June 7, 2011 3:03 PM

All replies

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

    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/

     

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 8, 2011 6:37 AM
  • so here is the next issue. I got my process working in a win form. It uses a few web pages like a user would, fills in textboxes, hits buttons, etc but... I have one issue.

    I need this to work as some kind of scheduled task but because the form includes the browser and the browser opens up dialog boxes for choosing a file for an upload control, it will not actually work unless you are physically logged in and looking at the desktop. Is there a way to do this without being logged in physically and make it work?

     

    Wednesday, June 8, 2011 5:22 PM
  • Since some operations will need the user permission or find something through windows handler, so you need logged in to let the windows show, then the handler will be created and be used.

    Or you can just post the request from url string, then you don't need so complex UI automation codes.

    For the URL string, you can use some tool capture it and then use it in your code, you can ref the following thread:

    http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/b948ce32-305b-4e6a-b5ef-96795f6042ba

     

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 9:02 AM
  • Alright, thanks for that above link, I was able to get this working using methods and ideas shown there. The main problem now is, it works on my machine, it works on another random XP machine but I can't get it to work 100% on the win2k3 server I am trying to run it on. 

    I can get it work on a server 2008 box as well. 

     

    IE7 issue is the only thing I can find but I have no other machines with IE7 only on them.

    Friday, June 10, 2011 5:38 PM
  • --> but I can't get it to work 100% on the win2k3 server

    What do you mean it cannot work 100%, do you mean it can work but would be fail several times in a windows 2003 server system?

    What about the others windows 2003 server systems?

    What caused it not work, is there any error message shown to you or shown in the event viewer?

    If there is, please show us one copy of them.

    If it cannot work 100%, then I think it would be the system permission problem, but you said you cannot get it to work 100%, it means it can work but would fail for times, right? Then it would be not a system permission problem, I think.

     

    --> IE7 issue is the only thing I can find but I have no other machines with IE7 only on them.

    What do you mean, let us direct to "IE7 problem" suddenly? Do you mean the IE7 cause this method cannot work 100% in windows 2003 server system? What about a win2003 with a IE6? How did you ensure it would be the IE7 problem?

    Or can you help us clarify your situations?

     

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 13, 2011 6:15 AM
  • Hi Zenuke,
    I am writing to check the status of the issue on your side. 
    What about this problem now? 
    Would you mind letting us know the result of the suggestions?
    Best wishes,

    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 16, 2011 5:35 AM