test in progress - some fixes

dev-linux
Ivan Maslov 2 years ago
parent fb9e15144c
commit 182c551ba7

@ -3,7 +3,7 @@ from selenium import webdriver, common
import os
import sys
from pyOpenRPA.Tools import CrossOS
from . import Screen
import time
UIO_WAIT_SEC_FLOAT = 60
@ -13,7 +13,7 @@ gBrowser:webdriver.Chrome = None
def BrowserChromeStart(inDriverExePathStr:str = None, inChromeExePathStr:str = None, inExtensionPathList:list = None, inProfilePathStr:str=None) -> webdriver.Chrome:
global gBrowser
lResourcePathStr = os.path.abspath(os.path.join(sys.executable, "..",".."))
lResourcePathStr = os.path.abspath(os.path.join(sys.executable, "..","..", ".."))
# Путь по умолчанию к портативному браузеру и драйверу (если скачивался репозиторий pyOpenRPA
if inDriverExePathStr == None: inDriverExePathStr = os.path.join(lResourcePathStr, "SeleniumWebDrivers", "Chrome", "chromedriver_win32 v84.0.4147.30", "chromedriver.exe")
if inChromeExePathStr == None: inChromeExePathStr = os.path.join(lResourcePathStr, "WChrome64-840414730", "App", "Chrome-bin", "chrome.exe")
@ -48,22 +48,24 @@ def PageScrollTo(inVerticalPxInt=0, inHorizontalPxInt=0):
def PageJSExecute(inJSStr):
global gBrowser
if gBrowser is not None: gBrowser.execute_script(inJSStr)
if gBrowser is not None: return gBrowser.execute_script(inJSStr)
def BrowserClose():
global gBrowser
if gBrowser is not None: gBrowser.quit()
def UIOByCSSList(inCSSStr, inUIO=None) -> list:
def UIOSelectorList(inUIOSelectorStr, inUIO=None) -> list:
lResultList = []
if inUIO is None:
global gBrowser
if gBrowser is not None:
gBrowser.find_elements_by_css_selector(css_selector=inCSSStr)
else: inUIO.find_elements_by_css_selector(css_selector=inCSSStr)
lResultList = gBrowser.find_elements_by_css_selector(css_selector=inUIOSelectorStr)
else: lResultList = inUIO.find_elements_by_css_selector(css_selector=inUIOSelectorStr)
return lResultList
def UIOByCSSFirst(inCSSStr, inUIO=None) -> list:
def UIOSelectorFirst(inUIOSelectorStr, inUIO=None) -> list:
lResult = None
lUIOList = UIOByCSSList(inCSSStr=inCSSStr, inUIO=inUIO)
lUIOList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr, inUIO=inUIO)
if len(lUIOList) > 0: lResult = lUIOList[0]
return lResult
@ -76,23 +78,35 @@ def UIOAttributeGet(inUIO, inAttributeStr) -> str:
def UIOClick(inUIO):
inUIO.click()
def UIOSelectorDraw(inUIOSelectorStr: str, inIsFirst:bool=False):
lList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr)
global gBrowser
lBrowserRect = gBrowser.get_window_rect()
lViewportHeightInt = PageJSExecute(inJSStr=f"return $(window).height();")
lBrowserRect["y"]= lBrowserRect["y"] + (lBrowserRect["height"] - lViewportHeightInt)
if inIsFirst == True and len(lList)>0: lList = [lList[0]]
for lItem in lList:
lRect = lItem.rect
lBox = Screen.BoxCreate(inTopInt=round(lRect['y']+lBrowserRect['y']), inLeftInt=round(lRect['x']+lBrowserRect['x']), inHeightInt=round(lRect['height']), inWidthInt=round(lRect['width']))
Screen.BoxDraw(inBox=lBox)
def UIOSelectorClick(inUIOSelectorStr: str):
PageJSExecute(inJSStr=f"document.querySelector('{inUIOSelectorStr}').click()")
def UIOSelectorWaitAppear(inUIOSelectorStr, inWaitSecFloat:float=UIO_WAIT_SEC_FLOAT, inWaitIntervalSecFloat:float = UIO_WAIT_INTERVAL_SEC_FLOAT):
def UIOSelectorWaitAppear(inUIOSelectorStr:str, inWaitSecFloat:float=UIO_WAIT_SEC_FLOAT, inWaitIntervalSecFloat:float = UIO_WAIT_INTERVAL_SEC_FLOAT):
lStartSecFloat = time.time()
lResultList=[]
while time.time() - lStartSecFloat < inWaitSecFloat:
lResultList = UIOByCSSList(inCSSStr=inUIOSelectorStr)
lResultList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr)
if len(lResultList)>0: break
time.sleep(inWaitIntervalSecFloat)
return lResultList
def UIOWaitDisappear(inUIOSelectorStr, inWaitSecFloat:float=UIO_WAIT_SEC_FLOAT, inWaitIntervalSecFloat:float = UIO_WAIT_INTERVAL_SEC_FLOAT):
def UIOSelectorWaitDisappear(inUIOSelectorStr:str, inWaitSecFloat:float=UIO_WAIT_SEC_FLOAT, inWaitIntervalSecFloat:float = UIO_WAIT_INTERVAL_SEC_FLOAT):
lStartSecFloat = time.time()
lResultList=[]
while time.time() - lStartSecFloat < inWaitSecFloat:
lResultList = UIOByCSSList(inCSSStr=inUIOSelectorStr)
lResultList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr)
if len(lResultList)==0: break
time.sleep(inWaitIntervalSecFloat)
return lResultList
Loading…
Cancel
Save