IPEasyUtility.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. using System;
  2. using System.Data;
  3. using System.Diagnostics;
  4. using System.Dynamic;
  5. using System.Linq;
  6. using OpenQA.Selenium;
  7. using OpenQA.Selenium.Chrome;
  8. namespace wispro.sp.utility
  9. {
  10. public class IPEasyUtility
  11. {
  12. public static void DownloadReport(string strId,string filename)
  13. {
  14. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  15. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  16. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  17. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  18. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  19. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  20. options.AddUserProfilePreference("intl.accept_languages", "nl");
  21. options.AddUserProfilePreference("disable-popup-blocking", "true");
  22. if (isheadless)
  23. {
  24. options.AddArgument("headless");
  25. }
  26. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  27. {
  28. try
  29. {
  30. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  31. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  32. //进入登录界面
  33. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  34. //输入用户名和密码
  35. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  36. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  37. //点击登录按钮
  38. driver.FindElement(By.Id("btnLogin")).Click();
  39. //关闭提示遮罩层
  40. driver.FindElement(By.Id("jpwClose")).Click();
  41. //点击顶部菜单栏中的报表管理菜单
  42. driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
  43. //点击左侧 自定义报表 菜单
  44. driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
  45. //切换到自定义报表Frame
  46. driver.SwitchTo().Frame(1);
  47. //调用报表导出JS
  48. ((IJavaScriptExecutor)driver).ExecuteScript($"Report.Export('{strId}');");
  49. //切换到弹出的导出报表窗口,点击导出按钮
  50. driver.SwitchTo().DefaultContent();
  51. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  52. driver.SwitchTo().Frame(ihg_export);
  53. driver.FindElement(By.Id("btnSubmit")).Click();
  54. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  55. while (true)
  56. {
  57. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
  58. if (!file.Exists || file.Length == 0)
  59. {
  60. System.Threading.Thread.Sleep(5000);
  61. }
  62. else
  63. {
  64. break;
  65. }
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. throw new Exception(ex.Message);
  71. }
  72. finally
  73. {
  74. killChromProcess();
  75. }
  76. }
  77. }
  78. /// <summary>
  79. /// 根据报表名称导出报表
  80. /// </summary>
  81. /// <param name="ReportName">报告名称</param>
  82. /// <param name="isModifyDate">是否手动修改日期范围</param>
  83. public static DataTable DownloadReport(string ReportName,bool isModifyDate)
  84. {
  85. DataTable retDatatable;
  86. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  87. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  88. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  89. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  90. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  91. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  92. options.AddUserProfilePreference("intl.accept_languages", "nl");
  93. options.AddUserProfilePreference("disable-popup-blocking", "true");
  94. if (isheadless)
  95. {
  96. options.AddArgument("headless");
  97. }
  98. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  99. {
  100. try
  101. {
  102. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  103. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  104. //进入登录界面
  105. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  106. //输入用户名和密码
  107. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  108. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  109. //点击登录按钮
  110. driver.FindElement(By.Id("btnLogin")).Click();
  111. //关闭提示遮罩层
  112. driver.FindElement(By.Id("jpwClose")).Click();
  113. //点击顶部菜单栏中的报表管理菜单
  114. driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
  115. //点击左侧 自定义报表 菜单
  116. driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
  117. //切换到自定义报表Frame
  118. driver.SwitchTo().Frame(1);
  119. var inputSearch = driver.FindElement(By.Id("customizedList_TxtSheetSearchKey"));
  120. inputSearch.SendKeys(ReportName);
  121. var btnSearch = driver.FindElement(By.ClassName("btn-search"));
  122. btnSearch.Click();
  123. var reportRecord = driver.FindElement(By.XPath($"//td[contains(text(),'{ReportName}')]"));
  124. reportRecord.Click();
  125. System.Threading.Thread.Sleep(1000);
  126. if (isModifyDate)
  127. {
  128. var btnEdit = driver.FindElement(By.ClassName("edit"));
  129. btnEdit.Click();
  130. System.Threading.Thread.Sleep(500);
  131. var doItemFinished = driver.FindElement(By.XPath("//span[contains(@objcvalue,'_date') and contains(@id,'ST;')]"));
  132. doItemFinished.Click();
  133. System.Threading.Thread.Sleep(500);
  134. var startDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_s_')]"));
  135. startDate.Click();
  136. System.Threading.Thread.Sleep(500);
  137. startDate.SendKeys(new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1).ToString("yyyy-MM-dd"));
  138. var endDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_e_')]"));//.Id("dt_e_4F8FE88D-9040-45F1-9723-45699BCD4CAF"));
  139. endDate.Click();
  140. System.Threading.Thread.Sleep(500);
  141. endDate.SendKeys(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1).ToString("yyyy-MM-dd"));
  142. var addDate = driver.FindElement(By.XPath("//a[contains(@onclick,'ReportSub.ConditionDTSelect')]"));
  143. addDate.Click();
  144. System.Threading.Thread.Sleep(500);
  145. var btnSave = driver.FindElement(By.Id("save"));
  146. btnSave.Click();
  147. System.Threading.Thread.Sleep(3000);
  148. }
  149. var linkExport = driver.FindElement(By.XPath("//a[contains(@onclick,'-') and @class='tbexcel']"));
  150. linkExport.Click();
  151. //切换到弹出的导出报表窗口,点击导出按钮
  152. driver.SwitchTo().DefaultContent();
  153. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  154. driver.SwitchTo().Frame(ihg_export);
  155. driver.FindElement(By.Id("btnSubmit")).Click();
  156. //切换到弹出的下载报表界面,点击下载按钮
  157. System.Threading.Thread.Sleep(3000);
  158. driver.SwitchTo().DefaultContent();
  159. var frameDownload = driver.FindElement(By.Name("DownloadList"));
  160. driver.SwitchTo().Frame(frameDownload);
  161. var firstTr = driver.FindElement(By.TagName("tr"));
  162. var tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  163. string strStatus = tdStatus.Text;
  164. while (strStatus.Trim() != "导出成功!")
  165. {
  166. System.Threading.Thread.Sleep(5000);
  167. firstTr = driver.FindElement(By.TagName("tr"));
  168. tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  169. strStatus = tdStatus.Text;
  170. }
  171. firstTr = driver.FindElement(By.TagName("tr"));
  172. firstTr.FindElement(By.XPath("//td/a[@title='下载']")).Click();
  173. //System.Threading.Thread.Sleep(5000);
  174. //btnDownload.Click();
  175. string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
  176. int iwaiting = 0;
  177. while (true)
  178. {
  179. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  180. if (!file.Exists || file.Length == 0)
  181. {
  182. System.Threading.Thread.Sleep(5000);
  183. iwaiting += 5000;
  184. if (iwaiting > 360000)
  185. {
  186. break;
  187. }
  188. }
  189. else
  190. {
  191. break;
  192. }
  193. }
  194. //删除下载记录
  195. firstTr = driver.FindElement(By.TagName("tr"));
  196. firstTr.FindElement(By.XPath("//td/a[@title='删除']")).Click();
  197. //System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  198. retDatatable = NPOIExcel.ExcelToDataTable(strFilePath.Replace("~", "_"),true);
  199. System.IO.File.Delete(strFilePath.Replace("~", "_"));
  200. }
  201. catch (Exception ex)
  202. {
  203. throw new Exception(ex.Message, ex);
  204. }
  205. finally
  206. {
  207. killChromProcess();
  208. }
  209. }
  210. return retDatatable;
  211. }
  212. /// <summary>
  213. /// 获取案件基本信息
  214. /// </summary>
  215. /// <param name="caseNo">我方文号</param>
  216. /// <returns></returns>
  217. public static dynamic GetCaseInfo(string caseNo)
  218. {
  219. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  220. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  221. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  222. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  223. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  224. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  225. options.AddUserProfilePreference("intl.accept_languages", "nl");
  226. options.AddUserProfilePreference("disable-popup-blocking", "true");
  227. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  228. if (isheadless)
  229. {
  230. options.AddArgument("headless");
  231. }
  232. dynamic retObject = new ExpandoObject();
  233. retObject.CaseNo = caseNo;
  234. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  235. {
  236. try
  237. {
  238. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
  239. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  240. //进入登录界面
  241. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  242. //输入用户名和密码
  243. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  244. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  245. //点击登录按钮
  246. driver.FindElement(By.Id("btnLogin")).Click();
  247. //关闭提示遮罩层
  248. driver.FindElement(By.Id("jpwClose")).Click();
  249. //点击顶部菜单栏中的案件管理菜单
  250. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  251. //点击左侧 查询 菜单
  252. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  253. //切换到自定义报表Frame
  254. driver.SwitchTo().Frame(1);
  255. var inputSearch = driver.FindElement(By.Id("case_volume"));
  256. inputSearch.SendKeys(caseNo);
  257. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  258. btnSearch.Click();
  259. var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
  260. caseLink.Click();
  261. System.Threading.Thread.Sleep(500);
  262. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  263. driver.FindElement(By.Id("libase")).Click();
  264. retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
  265. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  266. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  267. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  268. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  269. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  270. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  271. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  272. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  273. //select[@id='p_case_info__case_coefficient_id']
  274. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  275. }
  276. catch (Exception ex)
  277. {
  278. throw new Exception(ex.Message, ex);
  279. }
  280. finally
  281. {
  282. killChromProcess();
  283. }
  284. }
  285. return retObject;
  286. }
  287. /// <summary>
  288. /// 获取案件处理事项记录
  289. /// </summary>
  290. /// <param name="caseNo">我方文号</param>
  291. /// <param name="doItemName">处理事项</param>
  292. /// <returns></returns>
  293. public static dynamic GetPerformanceRecord(string caseNo,string doItemName,string caseStage=null)
  294. {
  295. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  296. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  297. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  298. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  299. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  300. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  301. options.AddUserProfilePreference("intl.accept_languages", "nl");
  302. options.AddUserProfilePreference("disable-popup-blocking", "true");
  303. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  304. if (isheadless)
  305. {
  306. options.AddArgument("headless");
  307. }
  308. dynamic retObject = new ExpandoObject();
  309. retObject.CaseNo = caseNo;
  310. retObject.DoItem = doItemName;
  311. using (var Service = ChromeDriverService.CreateDefaultService(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath")))
  312. {
  313. Service.Start();
  314. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(Service, options))
  315. {
  316. try
  317. {
  318. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
  319. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  320. //进入登录界面
  321. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  322. //输入用户名和密码
  323. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  324. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  325. //点击登录按钮
  326. driver.FindElement(By.Id("btnLogin")).Click();
  327. //关闭提示遮罩层
  328. driver.FindElement(By.Id("jpwClose")).Click();
  329. //点击顶部菜单栏中的案件管理菜单
  330. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  331. System.Threading.Thread.Sleep(500);
  332. //点击左侧 查询 菜单
  333. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  334. System.Threading.Thread.Sleep(500);
  335. //切换到自定义报表Frame
  336. driver.SwitchTo().Frame(1);
  337. var inputSearch = driver.FindElement(By.Id("case_volume"));
  338. inputSearch.SendKeys(caseNo);
  339. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  340. btnSearch.Click();
  341. System.Threading.Thread.Sleep(500);
  342. var caseLink = driver.FindElement(By.XPath($"//a[normalize-space()='{caseNo}']"));
  343. caseLink.Click();
  344. System.Threading.Thread.Sleep(500);
  345. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  346. var DoItemLinks = driver.FindElements(By.XPath($"//td[@colname='ctrl_proc'][normalize-space()='{doItemName}']"));
  347. if (DoItemLinks.Count > 0)
  348. {
  349. if (!string.IsNullOrEmpty(caseStage))
  350. {
  351. foreach (var DoItemLink in DoItemLinks)
  352. {
  353. var temCaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text;
  354. if (temCaseStage == caseStage)
  355. {
  356. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  357. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  358. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  359. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  360. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  361. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  362. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  363. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  364. DoItemLink.Click();
  365. break;
  366. }
  367. }
  368. }
  369. else
  370. {
  371. var DoItemLink = DoItemLinks[DoItemLinks.Count - 1];
  372. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  373. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  374. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  375. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  376. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  377. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  378. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  379. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  380. DoItemLink.Click();
  381. }
  382. }
  383. System.Threading.Thread.Sleep(500);
  384. retObject.FinalizationDate = driver.FindElement(By.Id("p_proc_info__finish_doc_date")).GetAttribute("value"); //定稿日
  385. retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
  386. retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
  387. retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
  388. retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
  389. driver.FindElement(By.Id("libase")).Click();
  390. System.Threading.Thread.Sleep(500);
  391. retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
  392. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  393. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  394. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  395. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  396. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  397. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  398. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  399. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  400. //select[@id='p_case_info__case_coefficient_id']
  401. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  402. }
  403. catch (Exception ex)
  404. {
  405. throw new Exception(ex.Message, ex);
  406. }
  407. finally
  408. {
  409. killChromProcess();
  410. }
  411. }
  412. Service.Dispose();
  413. }
  414. return retObject;
  415. }
  416. private static void killChromProcess()
  417. {
  418. try
  419. {
  420. Process[] workers = Process.GetProcessesByName("Chrome");
  421. foreach (Process worker in workers)
  422. {
  423. worker.Kill();
  424. worker.WaitForExit();
  425. worker.Dispose();
  426. }
  427. workers = Process.GetProcessesByName("Chromedriver");
  428. foreach (Process worker in workers)
  429. {
  430. worker.Kill();
  431. worker.WaitForExit();
  432. worker.Dispose();
  433. }
  434. }
  435. catch { }
  436. }
  437. private static string GetSelectText(IWebElement element)
  438. {
  439. var strValue = element.GetAttribute("value");
  440. if (string.IsNullOrEmpty(strValue))
  441. {
  442. return null;
  443. }
  444. var ops = element.FindElements(By.TagName("option"));
  445. foreach (var op in ops)
  446. {
  447. if (op.GetAttribute("value") == strValue)
  448. {
  449. return op.Text;
  450. }
  451. }
  452. return null;
  453. }
  454. }
  455. }