|
- using System;
- using System.Reflection;
- using System.IO;
-
-
- using OpenQA.Selenium;
- using OpenQA.Selenium.Chrome;
- using OpenQA.Selenium.Support.UI;
- using SeleniumExtras.WaitHelpers;
-
- namespace CSVDownloader.Web {
- class DriverFactory {
- public static ChromeDriver GetDriver() {
- CreateDir();
-
- var options = new ChromeOptions();
- // options.AddArgument("--headless");
- options.BinaryLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\chrome-win64\\chrome.exe";
- String download_dir = GetTmpDownloadDir();
- options.AddUserProfilePreference("download.default_directory", download_dir);
- ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
-
- WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
-
-
- return driver;
- }
-
- public static String GetTmpDownloadDir() {
- return Path.GetFullPath("tmp_download");
- }
-
- public static String GetDownloadDir() {
- return Path.GetFullPath("download");
- }
-
- private static void CreateDir() {
- String tmpdownload_dir = GetTmpDownloadDir();
- String download_dir = GetDownloadDir();
-
- if (!Directory.Exists(tmpdownload_dir)) {
- Directory.CreateDirectory(tmpdownload_dir);
- }
-
- if (!Directory.Exists(download_dir)) {
- Directory.CreateDirectory(download_dir);
- }
- }
- }
- }
|