fix: recovery functionality
This commit is contained in:
32
main.py
32
main.py
@@ -9,6 +9,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
|
from selenium.webdriver.remote.webelement import WebElement
|
||||||
|
|
||||||
from common.utils import *
|
from common.utils import *
|
||||||
from common.timer import Timer
|
from common.timer import Timer
|
||||||
@@ -149,6 +150,14 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
busy = driver.find_element(By.CSS_SELECTOR, ".io-ox-busy")
|
busy = driver.find_element(By.CSS_SELECTOR, ".io-ox-busy")
|
||||||
return busy
|
return busy
|
||||||
|
|
||||||
|
def catch(predicate, force=True):
|
||||||
|
try:
|
||||||
|
wait = WebDriverWait(driver, timeout=parameters['interval'])
|
||||||
|
return wait.until(predicate, 'Timeout')
|
||||||
|
except Exception as e:
|
||||||
|
if force: raise e
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
driver.switch_to.new_window('tab')
|
driver.switch_to.new_window('tab')
|
||||||
driver.set_page_load_timeout(parameters['timeout'])
|
driver.set_page_load_timeout(parameters['timeout'])
|
||||||
@@ -433,20 +442,22 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
progress['recipient'] = str(name)
|
progress['recipient'] = str(name)
|
||||||
logger.info('[%d/%d] Sending to %s', index-1, limit-1, email)
|
logger.info('[%d/%d] Sending to %s', index-1, limit-1, email)
|
||||||
clean = True
|
clean = True
|
||||||
|
error = None
|
||||||
|
|
||||||
if (target := get_address()) != parameters['account']:
|
if (target := get_address()) != parameters['account']:
|
||||||
e = MismatchedEmailAddress(target)
|
error = MismatchedEmailAddress(target)
|
||||||
raise e
|
if not options.get('recovery'): raise error
|
||||||
|
|
||||||
if (target := get_subject()) != subject:
|
if (target := get_subject()) != subject:
|
||||||
e = MismatchedEmailSubject(target)
|
error = MismatchedEmailSubject(target)
|
||||||
c = EC.presence_of_element_located
|
if not options.get('recovery'): raise error
|
||||||
if not options.get('recover'): raise e
|
|
||||||
|
|
||||||
|
if error is not None and (c := EC.presence_of_element_located):
|
||||||
|
click("li[data-id='virtual/standard'] > .subfolders li:nth-child(6) .folder-arrow", condition=c)
|
||||||
click("li[data-id='virtual/standard'] > .subfolders li:nth-child(6) li.folder:nth-child(1)", condition=c)
|
click("li[data-id='virtual/standard'] > .subfolders li:nth-child(6) li.folder:nth-child(1)", condition=c)
|
||||||
until(ready)
|
catch(ready, force=False)
|
||||||
click("ul[aria-label='List view'] li[data-index='0']", condition=c)
|
click("ul[aria-label='List view'] li[data-index='0']", condition=c)
|
||||||
until(ready)
|
catch(ready, force=False)
|
||||||
click("ul.classic-toolbar button[aria-label='More actions']", condition=c)
|
click("ul.classic-toolbar button[aria-label='More actions']", condition=c)
|
||||||
click(".abs + ul.dropdown-menu a[data-action='io.ox/mail/actions/copy']", condition=c)
|
click(".abs + ul.dropdown-menu a[data-action='io.ox/mail/actions/copy']", condition=c)
|
||||||
click(".modal-dialog ul.subfolders li[data-id='default0/Brouillons']", condition=c)
|
click(".modal-dialog ul.subfolders li[data-id='default0/Brouillons']", condition=c)
|
||||||
@@ -454,10 +465,10 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
click("li[data-id='default0/Brouillons']")
|
click("li[data-id='default0/Brouillons']")
|
||||||
|
|
||||||
for _ in range(parameters['attempts']):
|
for _ in range(parameters['attempts']):
|
||||||
until(ready)
|
catch(ready, force=False)
|
||||||
click("ul[aria-label='List view'] li[data-index='0']", condition=c)
|
click("ul[aria-label='List view'] li[data-index='0']", condition=c)
|
||||||
if get_subject() == subject: break
|
if get_subject() == subject: break
|
||||||
if not get_subject() == subject: raise e
|
if not get_subject() == subject: raise error
|
||||||
|
|
||||||
flow.do(Wait)
|
flow.do(Wait)
|
||||||
flow.react()
|
flow.react()
|
||||||
@@ -542,8 +553,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
w = WebDriverWait(driver, timeout=parameters['interval'])
|
alert: WebElement = catch(lambda x: x.find_element(By.CSS_SELECTOR, "div.io-ox-alert.io-ox-alert-error"))
|
||||||
alert = w.until(lambda x: x.find_element(By.CSS_SELECTOR, "div.io-ox-alert.io-ox-alert-error"))
|
|
||||||
message = alert.text.replace('\n', ' ')
|
message = alert.text.replace('\n', ' ')
|
||||||
|
|
||||||
cell(index, column.sent).value = '❌'
|
cell(index, column.sent).value = '❌'
|
||||||
|
|||||||
Reference in New Issue
Block a user