-
Notifications
You must be signed in to change notification settings - Fork 1
/
restore.py
80 lines (66 loc) · 3.41 KB
/
restore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from webdriver_manager.chrome import ChromeDriverManager
import time
import downloads
import private
URL = 'https://'+private.org+'.invisionapp.com/spaces/'+private.space+'/archived'
options = webdriver.ChromeOptions()
prefs = {'download.default_directory' : private.downloadDir}
options.add_experimental_option('prefs', prefs)
ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
# timeout after 20 seconds
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.set_window_position(0, 0)
driver.set_window_size(2000, 1200)
try:
driver.get(URL)
emailField = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="signin_email"]')))
pwField = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="signin_password"]')))
emailField.send_keys(private.username)
pwField.send_keys(private.pw)
submitButton = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app-shell:feature-root:auth-ui"]/div/div/div[1]/div/div/form/div[3]/button')))
submitButton.click()
sort = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app-shell:feature-root:home"]/div/section/div[4]/div[3]/div/div/div/div[2]/div/span')))
sort.click()
sortAZ = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app-shell:feature-root:home"]/div/section/div[4]/div[3]/div/div/div/div[2]/div/div/div/ul/li[4]/div/div')))
sortAZ.click()
windowHomeName = driver.execute_script("return document.getElementsByTagName('title')[0].text")
print('window name: '+windowHomeName)
def getProject(i):
project = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="app-shell:feature-root:home"]/div/section/div[4]/div[4]/div/div/div/div[1]/div/div/div['+str(i)+']/div')))
return project
def getProjectName(i):
project = getProject(i)
projectName = project.get_attribute('data-title')
return projectName
def restoreProject(i, index):
print('restoring '+str(index)+': '+getProjectName(i))
projectMore = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app-shell:feature-root:home"]/div/section/div[4]/div[4]/div/div/div/div[1]/div/div/div['+str(i)+']/div/div/article/a')))
projectMore.click()
time.sleep(1)
confirmButton = driver.find_element_by_xpath('//button[text()="Restore"]')
confirmButton.click()
# Set the upper bound to the estimated total count of the projects.
for i in range(1, 120):
project = lambda: wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="app-shell:feature-root:home"]/div/section/div[4]/div[4]/div/div/div/div[1]/div/div/div['+str(1)+']/div/div/article/a')))
projectLink = project()
driver.execute_script("arguments[0].focus()", projectLink)
time.sleep(1)
restoreProject(1, i)
time.sleep(1)
driver.back()
time.sleep(1)
driver.refresh()
print("good bye!")
driver.close()
except TimeoutException as ex:
print("Exception has been thrown." + str(ex))
driver.close()