-2

I want to choose a file from an already opened OpenFileDialog which is shown by the browser.

I want to use code similar to the following example:

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.InitialDirectory = "C:\\";

The problem is, that I cant access dialog. I can't reference it.

Edit: I use the selenium-webdriver for automated testing. But the fileDialog is presented by the website I want to test.

kame
  • 20,848
  • 33
  • 104
  • 159
  • 2
    When you say you can't access `dialog`, do you mean you don't have a reference to it, or something else? *Can* you get a reference to it? – Bradley Uffner Jun 20 '17 at 13:47
  • What do you mean by "I cant access dialog"? You need to show the dialog - see the example here : https://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog(v=vs.110).aspx – PaulF Jun 20 '17 at 13:48
  • yes, I edited the text. – kame Jun 20 '17 at 13:48
  • Can you show all of the relevant code. – PaulF Jun 20 '17 at 13:48
  • 1
    So does the dialog not belong to your program (what is "the browser" in this context)? If it does, *where* is it in your code? – Broots Waymb Jun 20 '17 at 13:50
  • 4
    Possible duplicate of [choose a File from OpenFileDialog with C#](https://stackoverflow.com/questions/37524651/choose-a-file-from-openfiledialog-with-c-sharp) – Anderson Pimentel Jun 20 '17 at 13:52
  • 2
    That fact that this is a *browser owned* open file dialog changes things significantly. Is it opened from javascript running in the page? – Bradley Uffner Jun 20 '17 at 14:00
  • Selenium WebDriver cannot handle objects outside the web browser - in your case, the dialog. If your intention is to upload a file, @Anderson's link would help you. – iamkenos Jun 21 '17 at 02:14

1 Answers1

0

without an OpenFileDialog you say? you have a few options for this..

one being a method i used here - https://github.com/Ricky310711/RDExplorer

You would need to create a new panel with a ListView and populate it with local folders and files, add a double click event handler to select the item selected by storing it in a string.