|
|
@ -3,7 +3,7 @@ from selenium import webdriver, common
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
from pyOpenRPA.Tools import CrossOS
|
|
|
|
from pyOpenRPA.Tools import CrossOS
|
|
|
|
|
|
|
|
from . import Screen
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
UIO_WAIT_SEC_FLOAT = 60
|
|
|
|
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:
|
|
|
|
def BrowserChromeStart(inDriverExePathStr:str = None, inChromeExePathStr:str = None, inExtensionPathList:list = None, inProfilePathStr:str=None) -> webdriver.Chrome:
|
|
|
|
global gBrowser
|
|
|
|
global gBrowser
|
|
|
|
lResourcePathStr = os.path.abspath(os.path.join(sys.executable, "..",".."))
|
|
|
|
lResourcePathStr = os.path.abspath(os.path.join(sys.executable, "..","..", ".."))
|
|
|
|
# Путь по умолчанию к портативному браузеру и драйверу (если скачивался репозиторий pyOpenRPA
|
|
|
|
# Путь по умолчанию к портативному браузеру и драйверу (если скачивался репозиторий pyOpenRPA
|
|
|
|
if inDriverExePathStr == None: inDriverExePathStr = os.path.join(lResourcePathStr, "SeleniumWebDrivers", "Chrome", "chromedriver_win32 v84.0.4147.30", "chromedriver.exe")
|
|
|
|
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")
|
|
|
|
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):
|
|
|
|
def PageJSExecute(inJSStr):
|
|
|
|
global gBrowser
|
|
|
|
global gBrowser
|
|
|
|
if gBrowser is not None: gBrowser.execute_script(inJSStr)
|
|
|
|
if gBrowser is not None: return gBrowser.execute_script(inJSStr)
|
|
|
|
|
|
|
|
|
|
|
|
def BrowserClose():
|
|
|
|
def BrowserClose():
|
|
|
|
global gBrowser
|
|
|
|
global gBrowser
|
|
|
|
if gBrowser is not None: gBrowser.quit()
|
|
|
|
if gBrowser is not None: gBrowser.quit()
|
|
|
|
|
|
|
|
|
|
|
|
def UIOByCSSList(inCSSStr, inUIO=None) -> list:
|
|
|
|
def UIOSelectorList(inUIOSelectorStr, inUIO=None) -> list:
|
|
|
|
|
|
|
|
lResultList = []
|
|
|
|
if inUIO is None:
|
|
|
|
if inUIO is None:
|
|
|
|
global gBrowser
|
|
|
|
global gBrowser
|
|
|
|
if gBrowser is not None:
|
|
|
|
if gBrowser is not None:
|
|
|
|
gBrowser.find_elements_by_css_selector(css_selector=inCSSStr)
|
|
|
|
lResultList = gBrowser.find_elements_by_css_selector(css_selector=inUIOSelectorStr)
|
|
|
|
else: inUIO.find_elements_by_css_selector(css_selector=inCSSStr)
|
|
|
|
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
|
|
|
|
lResult = None
|
|
|
|
lUIOList = UIOByCSSList(inCSSStr=inCSSStr, inUIO=inUIO)
|
|
|
|
lUIOList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr, inUIO=inUIO)
|
|
|
|
if len(lUIOList) > 0: lResult = lUIOList[0]
|
|
|
|
if len(lUIOList) > 0: lResult = lUIOList[0]
|
|
|
|
return lResult
|
|
|
|
return lResult
|
|
|
|
|
|
|
|
|
|
|
@ -76,23 +78,35 @@ def UIOAttributeGet(inUIO, inAttributeStr) -> str:
|
|
|
|
def UIOClick(inUIO):
|
|
|
|
def UIOClick(inUIO):
|
|
|
|
inUIO.click()
|
|
|
|
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):
|
|
|
|
def UIOSelectorClick(inUIOSelectorStr: str):
|
|
|
|
PageJSExecute(inJSStr=f"document.querySelector('{inUIOSelectorStr}').click()")
|
|
|
|
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()
|
|
|
|
lStartSecFloat = time.time()
|
|
|
|
lResultList=[]
|
|
|
|
lResultList=[]
|
|
|
|
while time.time() - lStartSecFloat < inWaitSecFloat:
|
|
|
|
while time.time() - lStartSecFloat < inWaitSecFloat:
|
|
|
|
lResultList = UIOByCSSList(inCSSStr=inUIOSelectorStr)
|
|
|
|
lResultList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr)
|
|
|
|
if len(lResultList)>0: break
|
|
|
|
if len(lResultList)>0: break
|
|
|
|
time.sleep(inWaitIntervalSecFloat)
|
|
|
|
time.sleep(inWaitIntervalSecFloat)
|
|
|
|
return lResultList
|
|
|
|
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()
|
|
|
|
lStartSecFloat = time.time()
|
|
|
|
lResultList=[]
|
|
|
|
lResultList=[]
|
|
|
|
while time.time() - lStartSecFloat < inWaitSecFloat:
|
|
|
|
while time.time() - lStartSecFloat < inWaitSecFloat:
|
|
|
|
lResultList = UIOByCSSList(inCSSStr=inUIOSelectorStr)
|
|
|
|
lResultList = UIOSelectorList(inUIOSelectorStr=inUIOSelectorStr)
|
|
|
|
if len(lResultList)==0: break
|
|
|
|
if len(lResultList)==0: break
|
|
|
|
time.sleep(inWaitIntervalSecFloat)
|
|
|
|
time.sleep(inWaitIntervalSecFloat)
|
|
|
|
return lResultList
|
|
|
|
return lResultList
|