Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.57 KB | None | 0 0
  1. Private Sub InserimentoCredenziali()
  2.  
  3.         Dim uiAutomation = New CUIAutomation()
  4.  
  5.         Dim username As String = "s_rpaprod"
  6.         Dim password As String = "8i-1sTLd"
  7.         Dim chromePointer = IntPtr.Zero
  8.  
  9.         While chromePointer = IntPtr.Zero
  10.             chromePointer = FindWindow("Chrome_WidgetWin_1", "contratti.amplifon.com - Google Chrome")
  11.         End While
  12.  
  13.         While True
  14.             Try
  15.                 Dim chromeElement = uiAutomation.ElementFromHandle(chromePointer)
  16.                 Dim chromeArray = chromeElement.FindAll(TreeScope.TreeScope_Descendants, uiAutomation.CreateTrueCondition())
  17.                 Dim nomeUtenteElement As IUIAutomationElement = Nothing
  18.                 Dim passwordElement As IUIAutomationElement = Nothing
  19.                 Dim accediElement As IUIAutomationElement = Nothing
  20.  
  21.                 For i = 0 To chromeArray.Length - 1
  22.                     Dim currentElement = chromeArray.GetElement(i)
  23.                     Dim currentName = currentElement.CurrentName
  24.                     Dim valuePattern = currentElement.GetCurrentPattern(10018)
  25.                     Dim invokePattern = currentElement.GetCurrentPattern(10000)
  26.  
  27.                     If currentName IsNot Nothing Then
  28.                         If (currentName.ToLower.Contains("nome utente") Or currentName.ToLower.Contains("user")) And valuePattern IsNot Nothing Then
  29.                             nomeUtenteElement = currentElement
  30.                         ElseIf (currentName.ToLower.Contains("password") Or currentName.ToLower.Contains("pass")) And valuePattern IsNot Nothing Then
  31.                             passwordElement = currentElement
  32.                         ElseIf (currentName.ToLower.Contains("accedi") Or currentName.ToLower.Contains("sign in")) And invokePattern IsNot Nothing Then
  33.                             accediElement = currentElement
  34.                         End If
  35.                     End If
  36.                 Next
  37.  
  38.                 Dim nomeUtentePattern = DirectCast(nomeUtenteElement.GetCurrentPattern(10018), IUIAutomationLegacyIAccessiblePattern)
  39.                 Dim passwordPattern = DirectCast(passwordElement.GetCurrentPattern(10018), IUIAutomationLegacyIAccessiblePattern)
  40.                 Dim accediPattern = DirectCast(accediElement.GetCurrentPattern(10000), IUIAutomationInvokePattern)
  41.  
  42.                 nomeUtentePattern.SetValue(username)
  43.                 passwordPattern.SetValue(password)
  44.                 accediPattern.Invoke()
  45.                 Exit While
  46.             Catch ex As Exception
  47.  
  48.             End Try
  49.         End While
  50.  
  51.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement