0

Hi I'm using Selenium Web Driver and Geckodriver to automate a task on Mozilla. When Geckodriver lauches an instance of Mozilla, there is no problem :

  • Account Login
  • Click on buttons
  • Import file (Problem appears after that).
  • Next code isn't compiled.

Problem : Mozilla closes itself after and Geckodriver re-launches Mozilla and does the same procedure (Account login, click on buttons ...) like an infinite loop.

I would like to correct it, any help would be greatly appreciated. Thank you !

FirefoxProfile fox = new FirefoxProfile();
fox.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;");
fox.SetPreference("browser.helperApps.alwaysAsk.force", false);
fox.SetPreference("browser.download.folderList", 2);
fox.SetPreference("browser.download.dir", temp);
using (var driver = new FirefoxDriver(new FirefoxBinary(@"C:\Mozilla Firefox\firefox.exe"), fox))
            {
               driver.Manage().Window.Maximize();
               driver.Navigate().GoToUrl("//");
               //Click on buttons without problems
               System.Threading.Thread.Sleep(5000);
               //Import file
               var inputUpload = driver.FindElementById("uploadedPrevisionsFileId-button");
               inputUpload.Click();
               //I put Thread.Sleep to wait until the element appears
               System.Threading.Thread.Sleep(3000);
               SendKeys.Send("C:/Test.xls");
               SendKeys.Send("{ENTER}");
               //HERE, Mozilla stops but I can see the file has been imported
               //Code ...
             }
//And it restarts a new instance of Mozilla which does the same thing
Ashenson
  • 9
  • 1

1 Answers1

0

I am confused by your upload code. Have you used this strategy with success in other browsers? Is this to upload a file through a browser window similar to this? enter image description here

If so selenium handles file IO by simply calling SendKeys() on the upload element. inputUpload.SendKey("C:/Test.xls");

I am unsure what would be causing the browser to close, but may I suggest using a testing framework such as NUnit? That way you can avoid the using block and let the framework manage testSetup and tearDown.

Buster
  • 685
  • 1
  • 5
  • 28
  • Sorry I tried to minimize my program. So, it's a Windows dialog which appears but I have to open a file then click on another button "import" in the website. However, my program works when I'm compiling it alone (I mean I have other functions which are maybe interfering with this code). Still, it's strange, whatever. Finally I divided my project in 2 parts and it works. Thank you for having taken the time to think about my question – Ashenson Jan 10 '17 at 13:44