public static void ChooseFile(AutomationElement mainWindow, string path)
        {
            if (mainWindow == null)
            {
                throw new ArgumentNullException("ChooseFile");
            }

            ElementActions.ClickElement(ElementFinder.TryFindElement(mainWindow, "Choose Files Загрузить", "button", DefaultTimeout.Add(DefaultTimeout)));

            var uploadDialog = ElementFinder.TryFindElement(mainWindow, "Open", "dialog", DefaultTimeout, TreeScope.Children);
            var address      = ElementFinder.TryFindElement(uploadDialog, "file name:", "edit", DefaultTimeout);

            //InsertText(address, path);
            //WORKAROUND:
            SendKeys.SendWait(path);

            ElementActions.ClickElement(ElementFinder.TryFindElement(uploadDialog, "Open", "button", DefaultTimeout));
        }
        public static void MonitorDownload(AutomationElement browserWindow)
        {
            if (browserWindow == null)
            {
                throw new ArgumentNullException("MonitorDownload");
            }

            Console.WriteLine("...Please wait ~2 minutes. Checking if file was uploaded before...");

            var replaceButton = ElementFinder.TryFindElement(browserWindow, "заменить ", "button", TimeSpan.FromSeconds(0));

            if (replaceButton != null)
            {
                ElementActions.ClickElement(replaceButton);
            }

            ElementFinder.TryFindElement(browserWindow, "загрузка завершена", "text", DefaultTimeout);

            Console.WriteLine("\nDone!");
        }
Пример #3
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Please pass path of the file to upload as command line parameter");
                return(3);
            }

            var filePath = Path.GetFullPath(args[0]);

            if (!File.Exists(filePath))
            {
                Console.WriteLine("File does not exist");
                return(4);
            }

            var browserProcess = Process.Start("chrome.exe", "https://disk.yandex.ru/ -incognito --force-renderer-accessibility");

            if (browserProcess == null)
            {
                return(1);
            }

            Thread.Sleep(YadiskActions.DefaultTimeout);

            AutomationElement browserWindow;

            try
            {
                browserWindow = AutomationElement.FromHandle(browserProcess.MainWindowHandle);
                Utilities.AlignWindowToLeft();
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Close all browser windows and relaunch the programm");
                Console.ReadKey();
                return(2);
            }

            try
            {
                YadiskActions.Login(browserWindow, LOGIN, Password);

                YadiskActions.DragFileFromExplorer(filePath, ElementFinder.TryFindElement(browserWindow, "Загрузить файлы", "text", YadiskActions.DefaultTimeout).Current.BoundingRectangle.TopLeft);

                YadiskActions.MonitorDownload(browserWindow);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Utilities.CannotOpenExplorerException e)
            {
                Console.WriteLine("Cannot open explorer!");
            }


            Console.WriteLine("Press any key to close the program...");
            Console.ReadKey();

            browserProcess.Kill();
            return(0);
        }