Jump to content

Aelc

Active Members
  • Posts

    185
  • Joined

  • Last visited

  • Days Won

    1

Aelc last won the day on April 6 2020

Aelc had the most liked content!

Profile Information

  • Location
    Germany

Recent Profile Visitors

679 profile views

Aelc's Achievements

Prodigy

Prodigy (4/7)

27

Reputation

  1. @Danp2 sorry was busy in other projects When i start the script with visual studio it works as expected. The output is shown in the console. Well the prob is i attach a website with selenium and login. So you wont be able to take a deeper look into it, but it's not neccessary i guess. Actually i want to know how it works with basic scripts. Thats my main script: from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common import options, service from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException from selenium import webdriver import os from time import sleep from datetime import datetime from datetime import date from Passport import User, Pass from classes import Button, Sidebar, Label, EndTime, StartTime, Chromedriver ####################################################### ***** GetTime ***** ##################################################### def GetTime(ret): now = datetime.now() if ret == "H": return int(now.strftime("%H")) elif ret == "M": return int(now.strftime("%M")) elif ret == "HM": return now.strftime("%H:%M") ####################################################### ***** GetinnerHTML ***** ##################################################### def GetinnerHTML(obj): if type(obj) is bool: return "" else: return obj.get_attribute("innerHTML") ####################################################### ***** GetElement ***** ####################################################### def GetElement(sSearch,sName,ShowDebug=True): try: elem = driver.find_element(sSearch,sName) return elem except NoSuchElementException: if ShowDebug: print ('Element"' + sName + '" nicht gefunden') Sleep(1) return False ########################################################## ***** Sleep ***** ######################################################### def Sleep(duration): import time time.sleep(duration) return ######################################################### ***** LogIN_OUT ***** ###################################################### def LogIN_OUT (elemXpath,innerHTMLtoCheck = "Starten", Executelink = Chromedriver.Options.LoginLink, reloadDefaultWebsite = True): print("********* " + innerHTMLtoCheck + "... *********") print("********* Try *********") try: Login_out = GetElement(By.XPATH,elemXpath) if (Login_out) != False: LoginHTML = GetinnerHTML(Login_out) if (LoginHTML) == innerHTMLtoCheck: Login_out.click() print("********* " + innerHTMLtoCheck + " failed... try to work around *********") return Login_out except NoSuchElementException: SideBarL = GetElement(Sidebar.search,Sidebar.name) if SideBarL.get_property("aria-expanded") == "false": driver.get(Executelink) if reloadDefaultWebsite == True: driver.get(Chromedriver.Options.DefaultLink) print("------------------ Except ------------------") print("------------------ Except ------------------") print("------------------ Except ------------------") ######################################################### ***** Double Print ***** ##################################################### def DblePrint(TXT): print ("") print (TXT) ######################################################### ***** StartupChrome ***** ##################################################### def StartChrome(link): chrome_options = webdriver.ChromeOptions() #chrome_options.add_argument('headless') chrome_options.add_argument('window-size=' + Chromedriver.Options.size) chrome_options.add_argument('--disable-default-apps') chrome_options.add_argument('user-data-dir=C:\\Users\\' + User._dir + '\\Desktop\\CHROME\\User data') global driver driver = webdriver.Chrome(Chromedriver.path, options=chrome_options) driver.get(Chromedriver.Options.DefaultLink) driver.set_page_load_timeout(25) StartChrome(Chromedriver.Options.DefaultLink) openZoom = True # Mainloop while driver: # Check URL if driver.current_url != Chromedriver.Options.DefaultLink: driver.get(Chromedriver.Options.DefaultLink) # Try extend login session ExtendButton = GetElement(By.XPATH,Button.MainPage.name,False) if ExtendButton: if ExtendButton.get_attribute("data-action") == "save": ExtendButton.click() # Get LoginElements SideBarL = GetElement(Sidebar.search,Sidebar.name) if SideBarL == False: Use = GetElement(User.search,User.name) Pas = GetElement(Pass.search,Pass.name) Btn = GetElement(By.XPATH,Button.MainPage.name) # Send Keys if (Use) != False and (Pas) != False and (Btn) != False: Use.send_keys(User.write) Pas.send_keys(Pass.write) if GetinnerHTML(Btn) == "Login": Btn.click() DblePrint("********* Login... *********") # set int for loop i = 0 # timeout website driver.set_page_load_timeout(25) # loop it! while i < 1: # Get Label Lab = GetElement(By.XPATH, Label.name,False) # Get Label Txt Label_TXT = GetinnerHTML(Lab) # long sleep if GetTime("H") != StartTime.h and GetTime ("H") != EndTime.h: DblePrint ("********* long sleep *********") print ("********* long sleep *********") print ("********* long sleep *********") Sle = 120 driver.get(Chromedriver.Options.DefaultLink) while Sle > 1: Sleep (1) Sle -= 1 print ("********* " + str(Sle) + " seconds *********") if Label_TXT == "Achtung Zeiterfassung starten!": break if Label_TXT == "Heute kein Unterricht!": DblePrint ("********* Sleep -> " + GetTime("HM") + " *********") Sleep(15) else: break DblePrint ("********* current time " + GetTime("HM") + " *********") Sleep (1) # "time start" if GetTime("H") == StartTime.h and GetTime("M") >= StartTime.m: print ("********* start time " + StartTime.hstr + ":" + StartTime.mstr + " *********") LogIN_OUT (Button.MainPage.name,"Starten",Chromedriver.Options.LoginLink,True) cards = driver.find_elements(By.XPATH,"//div[@class='card']") if openZoom == True: openZoom = False print ( '------------------------------------ Get "cards" ----------------------------------------------') result = driver.find_element(By.XPATH,"//div[@class='card']") for i in cards: CardsRaw = i.find_element(By.XPATH,".//h4[@class='card-title']/a") check = GetinnerHTML(CardsRaw) print (check) Startdate = check[-21:-11].split(".") Enddate = check[-10:].split(".") today = datetime.today() if(isinstance(Startdate,list) and isinstance(Enddate,list)): if Startdate[0].isdigit() and Startdate[1].isdigit() and Startdate[2].isdigit() and Enddate[0].isdigit() and Enddate[1].isdigit() and Enddate[2].isdigit() and len(Startdate) == 3 and len(Enddate) == 3: if ((today.day >= int(Startdate[0]) and today.day <= int(Enddate[0])) and (today.month == int(Startdate[1]) or today.month == int(Enddate[1])) and (today.year == int(Startdate[2]) or today.year == int(Enddate[2]))): print ( '------------------------------------ match found ----------------------------------------------') DblePrint (check) result = CardsRaw CardsRaw.click() driver.set_page_load_timeout(25) ZoomLink = driver.find_element(by=By.CLASS_NAME,value="zoom") DblePrint ('------------------------------------ found zoomlink ----------------------------------------------') if ZoomLink: ZoomLink.click() driver.set_page_load_timeout(25) Meeting = GetElement(By.XPATH,"//form[@target='_blank']") if(GetElement(By.XPATH,Button.MainPage.name)): driver.execute_script("arguments[0].setAttribute('target',arguments[1])",Meeting, "_self") Meet = GetElement(By.XPATH,Button.MainPage.name) if Meet: DblePrint ('------------------------------------ meeting avaible ----------------------------------------------') Meet.click() driver.set_page_load_timeout(25) lastone = GetElement(By.XPATH,"//div[@role='button']") if lastone: DblePrint ('------------------------------------ join ----------------------------------------------') lastone.click() driver.set_page_load_timeout(25) Sleep (2) break # "time end" if GetTime("H") == EndTime.h and GetTime("M") >= EndTime.m: print ("********* end time " + EndTime.hstr + ":" + EndTime.mstr + " *********") LogIN_OUT (Button.MainPage.name,"Beenden",Chromedriver.Options.LogoutLink,True) # quit driver driver.quit() You will need the classes.py aswell from os import name from selenium.webdriver.common.by import By from datetime import datetime from time import sleep class Chromedriver: path = '/chromedriver' class Options: size = "1920,1080" DefaultLink = "https://lernplattform.gfn.de/" LoginLink = DefaultLink + "?starten=1" LogoutLink = DefaultLink + "?stoppen=1" class Button: class MainPage: name = '//button[@class="btn btn-primary"]' search = By.XPATH class Label: name = '//div[@class="alert alert-warning"]' search = By.XPATH class EndTime: h = 16 m = 33 hstr = str(h) mstr = str(m) class StartTime: h = 8 m = 25 hstr = str(h) mstr = str(m) class Sidebar: name = "sidepreopen-control" search = By.ID and i stored the login in the passport.py (normally stored in a JSON) from selenium.webdriver.common.by import By class User: name = "username" search = By.ID write = "***MY-EMAIL***" _dir = "***MY-USERDIR***" class Pass: name = "password" search = By.ID write = "***MY-PASSWORD***" btw my first python project - im trying to learn i will show you the output aswell - is maybe easier to understand - instead to change the other inputs without any account to access. All it does is to press a button while logged in when the time has come and go the right course - starting zoom meeting. But does this matter? i would say no 😜 Greetings
  2. Tried it quickly and seems to work. The consolewrite() still only outputs the std_error and not the printouts from Python... but I'll take a deeper look laterThanks so far!
  3. sorry @Jos im to stupid to read - to tired
  4. Hey there! i'm struggling a bit while trying to get the Output out of the python console the funny thing is the stderrread is working ... any suggestions?
  5. Hello and Welcome to the forum, Maybe your MsgBox is full? You should use: ConsoleWrite($initxt & @crlf) for a better overview. I wouldn't recommend working with Msgboxes & Html code until it's full formated. also you should go step by step, when you get an error or not the value you wanted.To startup this should show you the full html code in the console of Scite: #include <Inet.au3> $initxt = _INetGetSource('https://google.de',1) $initxt = StringReplace($initxt, '>', ">" & @CRLF) $check = ConsoleWrite ($initxt & @CRLF) If it does, then you can go to modify with StringReplace or something.. I'm sure the problem isn't in the _InetGetSource() To get more specific help, i would need to know which website you want to access and what exactly you want to do. Regards
  6. i don't have the function, so i can't write an example ... normally you just have to change the $xpathForumLink like this.. ;==========Select "XYZ Software Inc.*IT-Applications*Finance Apps Admin"================== $xpathForumLink = ("//*[@data-testid='WhosOnDuty_GroupRow_checkbox_XYZ_Software_INC.*IT-Applications*Finance Apps Admin']") $aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE1, $xpathForumLink) _IEAction($aForumLink[0], "focus") _IEAction($aForumLink[0], "click") ;=================END============================== ;==========Select "XYZ Software Inc.*IT-Application Support Services*Application Integration Support"================== $xpathForumLink = ("//*[@data-testid='WhosOnDuty_GroupRow_checkbox_XYZ_Software_INC.*IT-Application Support Services*Application Integration Support']") $aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE1, $xpathForumLink) _IEAction($aForumLink[0], "focus") _IEAction($aForumLink[0], "click") ;=================END============================== ;==========Select "XYZ Software Inc.*IT-Application Support Services*Business Analytics Support"================== $xpathForumLink = ("//*[@data-testid='WhosOnDuty_GroupRow_checkbox_XYZ_Software_INC.*IT-Application Support Services*Business Analytics Support']") $aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE1, $xpathForumLink) _IEAction($aForumLink[0], "focus") _IEAction($aForumLink[0], "click") But still i don't know the site or the other values... i'm sadly not able to Clairvoyance. Also i'm sure there is a way with webdriver EDIT: i tried this with an own created element based on your posted element. i used webdriver where the element could be found
  7. well actually i thought you use Webdriver... 2nd: it would be much easier to post the site you want to access.. you can search the attributes aswell. try: with the different values or when you have other attributes with different values you also can change the @data-testid into it (+ the searching value). normally this should work too ("//body/div[@id='reactPage']/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]") ("//body/div[@id='reactPage']/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]") ("//body/div[@id='reactPage']/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[3]")
  8. which site? or show me another checkbox.. i need to see the difference. In emergency you can always use javascript
  9. well still without WM_SIZE, it doesn't flicker that much. or are there problems to simply use GuiCtrlSetPos()? a mix from both that works well for me ( win7 64-bit ) nevermind i got the problem with bigger pictures but it works if the Base Stats are at desktopsize #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISysWin.au3> _GDIPlus_Startup() Local Const $BASE_WIDTH = @DesktopWidth, $BASE_HEIGHT = @DesktopHeight - 65 Global $hImage = _GDIPlus_ImageLoadFromFile("Image.jpg") Global $iImageWidth = _GDIPlus_ImageGetWidth($hImage), $iImageHeight = _GDIPlus_ImageGetHeight($hImage) _ReduceLargeImage($hImage, $iImageWidth, $iImageHeight) Local $aPos[] = [$iImageWidth, $iImageHeight] If $iImageWidth > $BASE_WIDTH Or $iImageHeight > $BASE_HEIGHT Then $aPos = _EvaluateSize($BASE_WIDTH, $BASE_HEIGHT, $iImageWidth, $iImageHeight) EndIf Global $hGUI = GUICreate("", $aPos[0], $aPos[1], -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME)) GUISetBkColor(0x000000) Global $idPic = GUICtrlCreatePic("", 0, 0, $aPos[0], $aPos[1]) _SetImagetoCtrl($idPic, $hImage, $aPos[0], $aPos[1]) AdlibRegister("_ResizeImage", 5) GUISetState() While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch WEnd Func _ReduceLargeImage(ByRef $hImage, ByRef $iImageWidth, ByRef $iImageHeight) If $iImageWidth <= @DesktopWidth Or $iImageHeight <= @DesktopHeight Then Return Local $aPos = _EvaluateSize(@DesktopWidth, @DesktopHeight, $iImageWidth, $iImageHeight) Local $hResize = _GDIPlus_ImageResize($hImage, $aPos[0], $aPos[1]) _GDIPlus_ImageDispose($hImage) $hImage = $hResize $iImageWidth = $aPos[0] $iImageHeight = $aPos[1] EndFunc ;==>_ReduceLargeImage Func _EvaluateSize($iBaseWidth, $iBaseHeight, $iActualWidth, $iActualHeight) Local $iVal = $iBaseWidth / $iActualWidth * $iActualHeight If $iVal <= $iBaseHeight Then Return StringSplit($iBaseWidth & "|" & $iVal, "|", $STR_NOCOUNT) $iVal = $iBaseHeight / $iActualHeight * $iActualWidth Return StringSplit($iVal & "|" & $iBaseHeight, "|", $STR_NOCOUNT) EndFunc ;==>_EvaluateSize Func _SetImagetoCtrl($idPic, $hImage, $iWidth, $iHeight) Local $hResize = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hResize) _GDIPlus_ImageDispose($hResize) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) _WinAPI_DeleteObject($hHBitmap) EndFunc ;==>_SetImagetoCtrl Func _ResizeImage() Local $tRECT = _WinAPI_GetClientRect($hGUI) Local $iWidth = $tRECT.right - $tRECT.left + 1 Local $iHeight = $tRECT.bottom - $tRECT.top + 1 If $iWidth > $iImageWidth And $iHeight > $iImageHeight Then Local $aPos[] = [$iImageWidth, $iImageHeight] Else Local $aPos = _EvaluateSize($iWidth, $iHeight, $iImageWidth, $iImageHeight) EndIf Local $aIMGpos = ControlGetPos($hGUI, "", $idPic) If $aIMGpos[0] <> Int(($iWidth - $aPos[0]) / 2) Or $aIMGpos[1] <> Int(($iHeight - $aPos[1]) / 2) Or Int($aPos[0]) <> $aIMGpos[2] Or Int($aPos[1]) <> $aIMGpos[3] Then GUICtrlSetPos($idPic, Int(($iWidth - $aPos[0]) / 2), Int(($iHeight - $aPos[1]) / 2), $aPos[0], $aPos[1]) EndFunc ;==>_ResizeImage
  10. @Nine isn't $WM_SIZE lagging for you ? In my setup it does :/
  11. well not sure where you would use this, except you want a fullscreen GUI without controls... i mean you would have to resize the left an top also when you want to add some. anyway if i understood you right you are looking for something like #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISysWin.au3> Dim $__BMP[0], $__Image[0] Local $path = @ScriptDir & "\", $pic = $path & "images.png" Local $hPic _GDIPlus_Startup() $img = _GDIPlus_ImageLoadFromFile($pic) Global $hGUImain = GUICreate("", _GDIPlus_ImageGetWidth($img),_GDIPlus_ImageGetHeight($img),-1,-1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) GUISetBkColor(0x000000) _SetPicToCTRL($hPic, $pic, 0, 0) GUISetState(@SW_SHOW, $hGUImain) While 1 _SizeIMG($hPic) $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE For $i = 0 To UBound($__BMP) - 1 _WinAPI_DeleteObject($__BMP) Next _GDIPlus_Shutdown() GUIDelete($hGUImain) Exit EndSwitch WEnd Func _SizeIMG( $_hCTRL) Local $_aWIN_Size = WinGetClientSize($hGUImain) Local $_aIMG_Pos = ControlGetPos ( $hGUImain,"",$_hCTRL ) Local $Propotion = $_aIMG_Pos[2] / $_aIMG_Pos[3] If $_aWIN_Size[0]-10 < $_aIMG_Pos[2] Or $_aWIN_Size[0]-10 > $_aIMG_Pos[2] Then $_width_diff = $_aWIN_Size[0] If $_width_diff/$Propotion < $_aWIN_Size[1]-10 Then GUICtrlSetPos ( $_hCTRL,$_aIMG_Pos[0],$_aIMG_Pos[1],$_width_diff,$_width_diff/$Propotion) EndIf If $_aWIN_Size[1]-10 < $_aIMG_Pos[3] Or $_aWIN_Size[1]-10 > $_aIMG_Pos[3] Then $_height_diff = $_aWIN_Size[1] If $_height_diff*$Propotion < $_aWIN_Size[0]-10 Then GUICtrlSetPos ( $_hCTRL,$_aIMG_Pos[0],$_aIMG_Pos[1],$_height_diff*$Propotion,$_height_diff) EndIf EndFunc Func _SetPicToCTRL(ByRef $_aCTRL, $_aPic_Path, $x = 5, $y = 5, $w = False, $h = False) Local $_w = $w, $_h = $h If IsArray($_aPic_Path) And IsArray($_aCTRL) Then For $i = 0 To UBound($_aPic_Path) - 1 ReDim $__Image[UBound($__Image) + 1] ReDim $__BMP[UBound($__BMP) + 1] $__Image[UBound($__Image) - 1] = _GDIPlus_ImageLoadFromFile($_aPic_Path[$i]) If @error Then Return SetError(-1, 1, -1) $__BMP[UBound($__BMP) - 1] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($__Image[UBound($__Image) - 1]) If @error Then Return SetError(-1, 2, -1) If $w = False Then $_w = _GDIPlus_ImageGetWidth($_aPic_Path[$i]) If $h = False Then $_h = _GDIPlus_ImageGetHeight($_aPic_Path[$i]) $_aCTRL[$i] = GUICtrlCreatePic("", 0, 0, 10, 10) If @error Then Return SetError(-1, 3, -1) _WinAPI_DeleteObject(GUICtrlSendMsg($_aCTRL[$i], $STM_SETIMAGE, $IMAGE_BITMAP, $__BMP[UBound($__BMP) - 1])) If @error Then Return SetError(-1, 4, -1) GUICtrlSetPos($_aCTRL[$i], $x, $y, $_w, $_h) If @error Then Return SetError(-1, 5, -1) If Not $i = 0 Then GUICtrlSetState($_aCTRL[$i], $GUI_HIDE) Next ElseIf IsArray($_aPic_Path) And IsArray($_aCTRL) <> True Then SetError(-3, 1, -3) ElseIf IsArray($_aCTRL) And IsArray($_aPic_Path) <> True Then SetError(-3, 2, -3) Else ReDim $__Image[UBound($__Image) + 1] ReDim $__BMP[UBound($__BMP) + 1] $__Image[UBound($__Image) - 1] = _GDIPlus_ImageLoadFromFile($_aPic_Path) If @error Then Return SetError(-2, 1, -2) $__BMP[UBound($__BMP) - 1] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($__Image[UBound($__Image) - 1]) If @error Then Return SetError(-2, 2, -2) If $w = False Then $_w = _GDIPlus_ImageGetWidth($_aPic_Path) If $h = False Then $_h = _GDIPlus_ImageGetHeight($_aPic_Path) $_aCTRL = GUICtrlCreatePic("", 0, 0, 10, 10) If @error Then Return SetError(-2, 3, -2) _WinAPI_DeleteObject(GUICtrlSendMsg($_aCTRL, $STM_SETIMAGE, $IMAGE_BITMAP, $__BMP[UBound($__BMP) - 1])) If @error Then Return SetError(-2, 4, -2) GUICtrlSetPos($_aCTRL, $x, $y, $_w, $_h) If @error Then Return SetError(-2, 5, -2) EndIf Return True EndFunc ;==>_SetPicToCTRL btw the _SetPicToCTRL() func is for single picture paths and arrays... just took it from another script EDIT Hmm clarity... What do you mean? If your image has a resolution which is greater than your GUI it always should be clear regards
  12. your script isn't working at all.. if i understood right you are looking for something like While 1 For $i = 2 To 4 Local $cord = PixelSearch(1653, 575, 232, 99, "0x66121" & $i, 3) If IsArray($cord) Then MouseClick("right", $cord[0], $cord[1], 1, 1) Sleep(2000) Do Local $highlighted = PixelSearch(1065, 712, 1067, 714, 0x988327, 2) Sleep(10) Until IsArray($highlighted) MouseClick("left", 141, 1060) Sleep(1100) EndIf Next ; _turn() sleep(10) WEnd Func _turn() MouseMove(850, 475) MouseDown("right") MouseMove(1088, 475) MouseUp("right") EndFunc ;==>_turn not tested! actually im not sure what exactly you want but maybe this show you the way. i just rescripted the given script but the "else" aren't that clear since you didn't close the if statements EDIT: by the way i would set a hotkey to trigger it. I deactivated the constantly mousemove so far, because it would be annyoing
  13. please use the code tag next time when you post code... first of all you can't even run this script because you missed a " in your URL second you trying to access an unauthorized website so you will need an authentication to access it and 3rd point: where do you set up your send request with your screencapture? you will need to link it before send... Regards
×
×
  • Create New...