From 182c551ba73643b315372981dae65bf0c73e0dfa Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sun, 17 Jul 2022 02:24:09 +0300 Subject: [PATCH] test in progress - some fixes --- Sources/pyOpenRPA/Robot/UIWeb.py | 40 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/Sources/pyOpenRPA/Robot/UIWeb.py b/Sources/pyOpenRPA/Robot/UIWeb.py index 438f9bcc..33f6efec 100644 --- a/Sources/pyOpenRPA/Robot/UIWeb.py +++ b/Sources/pyOpenRPA/Robot/UIWeb.py @@ -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 \ No newline at end of file + return lResultList