browser


SUBMITTED BY: dbzdivik

DATE: Nov. 27, 2015, 5:28 a.m.

FORMAT: Text only

SIZE: 5.3 kB

HITS: 8715

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using Gecko;
  5. using Gecko.DOM;
  6. using System.IO;
  7. namespace Browser__OM_
  8. {
  9. public partial class Browser : Form
  10. {
  11. int counter = 0;
  12. public Browser()
  13. {
  14. Xpcom.Initialize(Application.StartupPath + "\\browser");
  15. //Directory.Delete (Application.StartupPath + "\\browser\\Cache");
  16. GeckoPreferences.Default["browser.xul.error_pages.enabled"] = true;
  17. GeckoPreferences.Default["security.warn_viewing_mixed"] = false;
  18. GeckoPreferences.Default["security.default_personal_cert"] = "Ask Never";
  19. GeckoPreferences.Default["capability.policy.strict.Window.alert"] = "noAccess";
  20. GeckoPreferences.Default["privacy.popups.showBrowserMessage"] = false;
  21. GeckoPreferences.Default["extensions.blocklist.enabled"] = false;
  22. GeckoPreferences.Default["security.enable_ssl2"] = true;
  23. GeckoPreferences.Default["security.warn_entering_weak"] = true;
  24. GeckoPreferences.Default["security.warn_viewing_mixed"] = false;
  25. GeckoPreferences.Default["dom.disable_open_during_load"] = true;
  26. GeckoPreferences.Default["dom.allow_scripts_to_close_windows"] = true;
  27. GeckoPreferences.Default["dom.popup_maximum"] = 0;
  28. GeckoPreferences.Default["browser.popups.showPopupBlocker"] = false;
  29. Directory.CreateDirectory(Application.StartupPath + "\\browser\\Cache");
  30. Xpcom.ProfileDirectory = (Application.StartupPath + "\\browser\\Cache");
  31. InitializeComponent();
  32. GeckoPreferences.Default["extensions.blocklist.enabled"] = false;
  33. }
  34. public Image GetImageId(GeckoWebBrowser Screen, GeckoHtmlElement a)
  35. {
  36. GeckoHtmlElement captchaImg = (GeckoHtmlElement)Screen.Document.GetElementById("cimage");
  37. Image hyt;
  38. try
  39. {
  40. hyt = (Bitmap)Image.FromStream(new MemoryStream(Gecko.Utils.SaveImageElement.ConvertGeckoImageElementToPng(Screen, captchaImg, 0, 0, captchaImg.OffsetWidth, captchaImg.OffsetHeight)));
  41. }
  42. catch
  43. {
  44. hyt = null;
  45. }
  46. return hyt;
  47. }
  48. private void Form1_Load(object sender, EventArgs e)
  49. {
  50. Time.MinDate = DateTime.Now.Date;
  51. Time.Value = DateTime.Now.AddDays(1).Date;
  52. Time.CustomFormat = "dd/MM/yyyy";
  53. Time.Format = DateTimePickerFormat.Custom;
  54. }
  55. private void Strt_Click(object sender, EventArgs e)
  56. {
  57. LogT.Start();
  58. }
  59. private void LogT_Tick(object sender, EventArgs e)
  60. {
  61. if (Screen.IsBusy == false)
  62. {
  63. counter++;
  64. if (counter == 1)
  65. {
  66. Screen.Navigate("https://www.irctc.co.in/eticketing/loginHome.jsf");
  67. }
  68. if (counter == 2)
  69. {
  70. Image cimg = hyt;
  71. }
  72. }
  73. }
  74. private void Login_Click(object sender, EventArgs e)
  75. {
  76. SinT.Start();
  77. }
  78. private void Clock_Tick(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. if (Screen.IsBusy == false)
  83. {
  84. counter++;
  85. if (counter == 1)
  86. {
  87. GeckoInputElement name = new GeckoInputElement(Screen.Document.GetElementsByName("j_username")[0].DomObject);
  88. name.Value = usrnm.Text;
  89. GeckoInputElement word = new GeckoInputElement(Screen.Document.GetElementsByName("j_password")[0].DomObject);
  90. word.Value = psswd.Text;
  91. GeckoInputElement cap = new GeckoInputElement(Screen.Document.GetElementsByName("j_captcha")[0].DomObject);
  92. cap.Value = cptch.Text;
  93. Screen.Navigate("javascript:void(document.getElementsByName('button')[0].click() ) ");
  94. }
  95. if (counter == 2)
  96. {
  97. GeckoInputElement from = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:fromStation")[0].DomObject);
  98. from.Value = Start.Text;
  99. GeckoInputElement to = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:toStation")[0].DomObject);
  100. to.Value = End.Text;
  101. GeckoInputElement date = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:journeyDateInputDate")[0].DomObject);
  102. date.Value = Time.Text;
  103. Screen.Navigate("javascript:void(document.getElementsByName('jpform:jpsubmit')[0].click() ) ");
  104. }
  105. }
  106. }
  107. catch
  108. {
  109. MessageBox.Show("Exception");
  110. }
  111. }
  112. private void textBox4_TextChanged(object sender, EventArgs e)
  113. {
  114. }
  115. }
  116. }

comments powered by Disqus