選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

56 行
1.5KB

  1. using System;
  2. using System.Reflection;
  3. using System.IO;
  4. using OpenQA.Selenium;
  5. using OpenQA.Selenium.Chrome;
  6. using OpenQA.Selenium.Support.UI;
  7. using SeleniumExtras.WaitHelpers;
  8. namespace CSVDownloader.Web {
  9. class DriverFactory {
  10. public static ChromeDriver GetDriver()
  11. {
  12. CreateDir();
  13. var options = new ChromeOptions();
  14. // options.AddArgument("--headless");
  15. String download_dir = GetTmpDownloadDir();
  16. options.AddUserProfilePreference("download.default_directory", download_dir);
  17. ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
  18. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
  19. return driver;
  20. }
  21. public static String GetTmpDownloadDir()
  22. {
  23. return Path.GetFullPath("tmp_download");
  24. }
  25. public static String GetDownloadDir()
  26. {
  27. return Path.GetFullPath("download");
  28. }
  29. private static void CreateDir()
  30. {
  31. String tmpdownload_dir = GetTmpDownloadDir();
  32. String download_dir = GetDownloadDir();
  33. if (!Directory.Exists(tmpdownload_dir))
  34. {
  35. Directory.CreateDirectory(tmpdownload_dir);
  36. }
  37. if (!Directory.Exists(download_dir))
  38. {
  39. Directory.CreateDirectory(download_dir);
  40. }
  41. }
  42. }
  43. }