Hallo Community,
bin ganz neu im Forum und recht neu im Thema AutoIT. Nun komme ich echt nicht weiter und hoffe hier auf Hilfe zu stoßen.
Ziel: Script soll 3 Firefox fenster öffnen, sich anmelden, werte setzen, die Fenster an bestimme Stellen platzieren und sich beenden.
Das Script habe ich kompiliert, local 100mal getestet und dann ca 30mal auf dem Rechner auf dem es auch laufen soll.
Ergebnis: Funktioniert wunderbar.
Problem1: 2 Wochen später funktioniert es nur noch bedingt. Es dauert viel länger als zuvor und er verhaut die einstellungen der Fensterposition.
Problem2: Die .exe wollte ich auf einem dritten Rechner heute testen und er schafft den _FFConnect nicht mehr. Auf dem selber rechner das Script (.au3) funktioniert ohne probleme.
Hier der Code:
Da dies mein erstes Script war, entschuldigt bitte den nicht immer ganz sauberen code
Spoiler anzeigen
#Include <FF.au3>
#include <FFEx.au3>
#include <Array.au3>
;- Variabeln
;------------------------------
Dim $conf_arg[50];- configfile variable, siehe unten für beschreibung
DIM $sdhwnd[3];-
Dim $mozstr
;- HotKeys
;------------------------------
HotKeySet("{ESC}", "Terminate");- Hotkey ESC, bei drücken funktionsaufruf Terminate. Beendet Script
;- Programm
;------------------------------
$mozstr = _MozRepl_Detect();- Rückgabewert ob Installation von Add-ON vorhanden.
If $mozstr <> 1 then;- Falls Add-on nicht installiert ist, script beenden. Installation von Addon vorher über die funktion gestartet
exit 0
Endif
read_config();- Auslesen des Logfiles, Prüft ob Benutzername via INI vorgegeben ist.
[/autoit] [autoit][/autoit] [autoit]if $conf_arg[0] = "" Then;- Falls kein Benutzername in der Ini angegeben ist, inbux box mit nachfrage nach Benutzer
$conf_arg[0] = InputBox("Security Check", "Enter the Username")
EndIf
$passwd = InputBox("Security Check", "Enter the password for " & $conf_arg[0], "", "*");- Passwortnachfrage für den Benutzer
ff_open();- Funktionsaufruf zum öffnen der Fenster und Login
ff_configure();- Configuriert die Fenster
_FFDisConnect();- Disconnect vom Add-On
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];- Funktionen
;-------------------------------
Func ff_open()
for $i = 0 to 2
_FFStart()
If _FFConnect(Default, Default, 5000) Then;- connect zum Addon
_FFOpenURL("")
_FFSetValue($conf_arg[0], "userName","name");-\
_FFSetValue($passwd, "password","name");- > Login
if $i <> 0 then _FFFormSubmit(0,"index","submit",False);-/
$sdhwnd[$i] = WinGetHandle("[active]");- Speichert die Window handle nummer, zum identifizieren der jeweiligen fenster.
if $i=0 then;- Beim ersten Fenster wird geprüft ob der Benutzername/PW korrekt ist, ansonsten wird der Anmeldevorgang / script abgebrochen.
_FFFormSubmit(0,"index","submit")
$sHTML = _FFReadHTML()
$result = StringInStr($sHTML, "Invalid Password or Username")
If $result <> 0 then
MsgBox(0,"Passwort oder Benutzername Falsch","Passwort oder Benutzername Falsch. Bitte überprüfen Sie Ihre Eingaben und starten Sie das Programm neu.")
Exit 0
Else
$result = StringInStr($sHTML, "already logged in with another")
if $result <> 0 Then
MsgBox(0,"Bereits eingeloggt","Sie sind bereits mit einem anderen User angemeldet. Bitte melden Sie sich erst aus und starten Sie das Programm neu.")
Exit 0
EndIf
EndIf
Endif
Else
MsgBox(64, "", "Can't connect to FireFox!")
Exit 0
EndIf
next
EndFunc
Func ff_configure()
$i = 0
for $i = 0 to 2
if $i = 0 Then ;(Erstes Fenster)
local $width=512
local $height=768
local $posy="0"
local $posx= 144
local $url=""
local $value="NOT IN ('')"
local $fname="ContractElementShortName"
ElseIf $i = 1 Then;(Zweites Fenster)
local $width=512
local $height= 768
local $posy=512
local $posx= 144
local $url=""
local $value=@YEAR & "-" & @MON & "-" & @MDAY
local $value2=@YEAR + 1 & "-" & @MON & "-" & @MDAY
local $fname="SPScheduledStartTime.From"
local $tname="SPScheduledStartTime.To"
ElseIf $i = 2 Then; (Drittes Fenster)
local $width=1024
local $height=599
local $posy="0"
local $posx= -215
local $url=""
EndIf
WinActivate($sdhwnd[$i])
sleep(100)
If _FFConnect(Default, Default, 5000) Then
If _FFLoadWait() Then
_FFOpenURL("" & $url)
if $i < 2 Then;- Einstellung der ersten 2 fenster
siteload()
sleep(1000)
buttoncheck()
_FFSetValue($value,$fname,"name")
if $i = 1 then _FFSetValue($value2,$tname,"name")
_FFClick("SubmitSelect","name")
siteload()
_FFCmd(')")
siteload()
sleep(500)
ElseIf $i = 2 Then;- Einstellung des Dritte Fenster.
siteload()
buttoncheck()
siteload()
_FFCmd("')")
siteload()
EndIf
EndIF
EndIf
WinMove($sdhwnd[$i], "", $posy, $posx, $width, $height)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Next
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func siteload()
;###
;###
;###
local $j
Do
$j = 0
$sHTML = _FFReadHTML()
$result = StringInStr($sHTML,"ListBeanName")
if $result = 0 Then
$j = 0
$result2 = StringInStr($sHTML,"BITTE WARTEN")
if $result2 > 0 then
$j = 1
EndIf
Else
$j = 1
$result2 = StringInStr($sHTML,"BITTE WARTEN")
if $result2 > 0 then
$j = 1
EndIf
EndIf
Until $j = 1
EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func buttoncheck()
;###
;### Überprüft ob hfp-button aktiv ist und betätigt ihn ggf.
;###
$result5 = "0"
$checkHTML2 = "0"
$checkHTML2 = _FFReadHTML()
$result5 = StringInStr($checkHTML2, "hfp-button-show")
sleep(100)
if $result5 > 0 Then
_FFClick("","id")
EndIf
EndFunc
Func Terminate()
Exit 0
EndFunc
Func _MozRepl_Detect($sProfile = "default", $bInstall = True , $sXPI = "http://repo.hyperstruct.net/mozrepl/1.0/mozrepl.xpi")
[/autoit] [autoit][/autoit] [autoit]If $sProfile = "" Then $sProfile = "default"
Local $sIni_Path = @AppDataDir & "\Mozilla\Firefox\"
Local $var = IniReadSectionNames($sIni_Path & "\profiles.ini")
If @error Then
MsgBox(4096, "", "Error occurred, probably no Firefox INI file.")
Else
For $i = 1 To $var[0]
Local $Ini_ = IniRead($sIni_Path & "\profiles.ini", $var[$i], "Name", "Error")
If $Ini_ = $sProfile Then
Local $sPath_folder = IniRead($sIni_Path & "\profiles.ini", $var[$i], "Path", "Error") ;Profile dir
ExitLoop
EndIf
Next
EndIf
If $bInstall Then
Local $sHKLM = "HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox"
Local $sFFExe = RegRead($sHKLM & "\" & RegRead($sHKLM, "CurrentVersion") & "\Main", "PathToExe")
Local $sCommand = StringFormat('"%s" "%s"',$sFFExe, $sXPI)
EndIf
If StringLeft($sPath_folder, = "Profiles" Then
If FileExists($sIni_Path & $sPath_folder & "\extensions\mozrepl@hyperstruct.net") Then
Return 1
Else
If $bInstall Then Return Run($sCommand)
Return 0
EndIf
Else
If FileExists($sPath_folder & "\extensions\mozrepl@hyperstruct.net") Then
Return 1
Else
If $bInstall Then Return Run($sCommand)
Return 0
EndIf
EndIf
EndFunc