Guest User

Untitled

a guest
Oct 15th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public Form1()
  2. {
  3.  
  4. InitializeComponent();
  5.  
  6. webBrowser1.Navigate("https://mese.webuntis.com/WebUntis/?school=HSS%20Freudenstadt#/basic/main");
  7. while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
  8. {
  9. Application.DoEvents();
  10. }
  11.  
  12. GetElementBy("button", "Login", "title").InvokeMember("Click");
  13. while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
  14. {
  15. Application.DoEvents();
  16. }
  17.  
  18. var Username = GetInputElement("Benutzer");
  19.  
  20. string UN = "xxxxx";
  21.  
  22. Username.SetAttribute("value",UN);
  23.  
  24.  
  25.  
  26. var Password = GetInputElement("Passwort");
  27. string PWD = "yyyyy";
  28. Password.SetAttribute("value",PWD);
  29.  
  30. GetElementBy("button", "submit", "type").InvokeMember("Click");
  31.  
  32. }}
  33.  
  34.  
  35. public HtmlElement GetElementBy(string Type, string Name, string Attribute)
  36. {
  37.  
  38. HtmlElementCollection theElementCollection = default(HtmlElementCollection);
  39. theElementCollection = webBrowser1.Document.GetElementsByTagName(Type);
  40. HtmlElement ReturnElement = null;
  41. foreach (HtmlElement curElement in theElementCollection)
  42. {
  43. if (curElement.GetAttribute(Attribute).ToString() == Name)
  44. {
  45. ReturnElement = curElement;
  46. break;
  47. }
  48.  
  49. }
  50. if (ReturnElement != null)
  51. {
  52. return ReturnElement;
  53. }
  54. else
  55. {
  56. return null;
  57. }
  58.  
  59. }
  60.  
  61. public HtmlElement GetInputElement(string Name)
  62. {
  63. HtmlElementCollection htmlcol = webBrowser1.Document.GetElementsByTagName("input");
  64. HtmlElement returnElement = null;
  65. for (int i = 0; i < htmlcol.Count; i++)
  66. {
  67. if (htmlcol[i].OuterHtml.Contains(Name))
  68. {
  69. returnElement = htmlcol[i];
  70. }
  71.  
  72. }
  73. if (returnElement != null)
  74. {
  75. return returnElement;
  76. }
  77. else
  78. {
  79. return null;
  80. }
  81.  
  82. }
Add Comment
Please, Sign In to add comment