Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 12:08

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



GeckoWebBrowser auto login *help*

Discussion on GeckoWebBrowser auto login *help* within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2018
Posts: 1
Received Thanks: 0
GeckoWebBrowser auto login *help*


Hallo, ich bin gerade dabei ein neues Projekt zu starten und stecke an folgendes fest:

Auto Login auf https Site (Ogame.de)
Nach Programm Start soll er die Website erstmal komplett laden und danach den Login() abfeuern
Er soll die Login Daten aus einer TextBox lesen und den Server aus der ComboBox.

"Main Form"
Code:
Imports Gecko
Imports Gecko.Events
Imports System.IO

Public Class Main
    Sub New()
        InitializeComponent()
        Xpcom.Initialize(Environment.CurrentDirectory + "/xulrunner")
    End Sub

    Dim UC As New UserConfig

#Region "GeckoWebBrowser"
    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GeckoWebBrowser1.Navigate("https://de.ogame.gameforge.com")
        GeckoWebBrowser1.Navigate("javascript:void(document.getElementsByTagName('iframe')[0].setAttribute('src', 'about:blank'))")
    End Sub
#End Region

#Region "Login"
    Public Sub Login()
        GeckoWebBrowser1.Document.GetElementById("usernameLogin").SetAttribute("value", Settings.FlatTextBox1.Text)
        GeckoWebBrowser1.Document.GetElementById("passwordLogin").SetAttribute("value", Settings.FlatTextBox2.Text)
        SelectServer()
    End Sub

    Public Sub SelectServer()
        Dim dropdown = GeckoWebBrowser1.Document.GetElementsByTagName("option")
        dropdown(Settings.FlatComboBox1.TabIndex).SetAttribute("selected", "selected")
    End Sub
#End Region

    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
        Settings.Show()
    End Sub
End Class
So wie der Code jetzt da steht, startet er das Programm ganz normal und Gecko navigiert ohne probleme auf die URL

ABER

wenn ich jetzt die Login() sub in Main_Load schreibe, gibt er sofort folgende Fehlermeldung:
Quote:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Mit Verweis auf die Public Sub Login()

Soweit mir bekannt ist und ich nicht falsch liege, fehlt mir ein Addhandler und DocumentCompleted ?
Ich hatte das vor 2 Jahren mal zum laufen gebracht aber bin zulange raus und mir fällt einfach nicht ein was und wo der fehler ist

UserConfig wo der Code zum Speichern der Daten drin steht, sieht wie folgt aus:

Code:
Imports Gecko
Imports Skybound.Gecko
Imports System.IO

Public Class UserConfig

    Dim Gecko As New Gecko.GeckoWebBrowser
    Dim sPath As String = ".\Resources"
    Dim filepath As String = ".\Resources\Config\cfg.ini"


#Region "Create Folder & File"
    Public Sub CreateFile()
        If Not System.IO.File.Exists(filepath) Then
            System.IO.File.Create(filepath).Dispose()
        End If
    End Sub

    Public Sub CreateFolder()
        If (My.Computer.FileSystem.DirectoryExists(sPath) = False) Then
            My.Computer.FileSystem.CreateDirectory(sPath + "/Config")
        Else
           'Something else happens, because the folder exists
        End If
    End Sub
#End Region



#Region "Script Save and Load"

    'Only important for Coder

    Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
    Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32


    Public Function INI_ReadValueFromFile(ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strFile As String) As String
        Dim strTemp As String = Space(1024), lLength As Integer
        lLength = GetPrivateProfileString(strSection, strKey, strDefault, strTemp, strTemp.Length, strFile)
        Return (strTemp.Substring(0, lLength))
    End Function

    Public Function INI_WriteValueToFile(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String, ByVal strFile As String) As Boolean
        Return (Not (WritePrivateProfileString(strSection, strKey, strValue, strFile) = 0))
    End Function

#Region "Save"
    Public Sub SaveUserSettings()
        INI_WriteValueToFile("User Data", "AccountName", Settings.FlatTextBox1.Text, ".\Resources\Config\cfg.ini")
        INI_WriteValueToFile("User Data", "AccountPasswort", Settings.FlatTextBox2.Text, ".\Resources\Config\cfg.ini")
        INI_WriteValueToFile("User Data", "ServerID", Settings.FlatComboBox1.SelectedItem, ".\Resources\Config\cfg.ini")
    End Sub
#End Region

#Region "Load"
    Public Sub LoadUserSettings()
        Settings.FlatTextBox1.Text = INI_ReadValueFromFile("User Data", "AccountName", "", ".\Resources\Config\cfg.ini")
        Settings.FlatTextBox2.Text = INI_ReadValueFromFile("User Data", "AccountPasswort", "", ".\Resources\Config\cfg.ini")
        Settings.FlatComboBox1.SelectedItem = INI_ReadValueFromFile("User Data", "ServerID", "", ".\Resources\Config\cfg.ini")
    End Sub
#End Region
#End Region

End Class
Wenn Ihr mehr Info's braucht, einfach schreiben! 8)

Thanks alot buddys


-Universe- is offline  
Old 03/31/2018, 13:20   #2



 
Serraniel's Avatar
 
elite*gold: 0
The Black Market: 205/1/0
Join Date: May 2010
Posts: 6,853
Received Thanks: 5,106
Arrow General Coding -> .NET Languages

#moved


Bezüglich des Nullpointer Fehlers: Du versuchst halt Elemente im Dom zu finden, welche existieren weil die Website in der Schnelle kaum fertig geladen haben kann. Dadurch sind die Elemente im DOM nicht vorhanden und können nicht gefunden werden und somit in deinem Code null. Ein DocumentCompleted Handler ist hier das was du brauchst, wie du selber schon sagtest. Der Login an sicht funktioniert technisch, z. B. wenn du die Login per Button press aufrufst?

Im Allgemeinen würde ich dir zusätzlich aber davon abraten, nen Webbrowser zu verwenden und stattdessen einfach mit Webrequests zu arbeiten, die entsprechende Posts und Gets an den Server senden. Das spart deutlich Resourcen gegenüber eines Webbrowsers und du bist nciht abhängig von deren DOM-Struktur.
Serraniel is offline  
Thanks
1 User
Old 04/03/2018, 04:36   #3

 
Nanoxx™'s Avatar
 
elite*gold: 15
Join Date: Feb 2013
Posts: 2,880
Received Thanks: 465
Mit CefSharp ist es einfacher...

Für Username / PW
PHP Code:
CEF.ExecuteScriptAsync("document.getElementById('usernameLogin').value = 'Username';"
Und für den Server
PHP Code:
document.getElementById('serverLogin').value '
                                                                                            Aquarius                                                                                    '

Nanoxx™ is offline  
Reply


Similar Threads Similar Threads
[TOOL] AutoClient V3 - Auto call, auto pick, auto login... just everything
11/08/2015 - League of Legends Hacks, Bots, Cheats & Exploits - 30 Replies
Hello there. I am about to release version 3 of my PVP.net Client automation tool. tl;dr Download Videos FAQ Documentation Report a problem https://www.youtube.com/watch?v=7g89-K8kPGA
Shaiya MultiBot v1.6#Auto potion,auto collection,auto stroke,auto skill
06/01/2012 - Shaiya Hacks, Bots, Cheats & Exploits - 12 Replies
http://d1205.hizliresim.com/x/5/5bjkl.jpg Hello everyone friends. I took off and I wanted to share the new version of Hilemizin. Other editions, a new difference: * Layout option 2.Skill. One trick from Image; http://c1205.hizliresim.com/x/4/59sgl.jpg Use the same fashion as yet. Slot {1} / Flat Beat Flat Beat Talent = 1 you put in the game. That it is the other options we.



All times are GMT +1. The time now is 12:09.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.