Skip to content

Instantly share code, notes, and snippets.

@vfreex
Created September 14, 2019 08:30
Show Gist options
  • Save vfreex/358ba2d6ef349e46db1fe4186ee1f3b0 to your computer and use it in GitHub Desktop.
Save vfreex/358ba2d6ef349e46db1fe4186ee1f3b0 to your computer and use it in GitHub Desktop.
import time
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.common import exceptions as EX
if __name__ == '__main__':
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=./my-profile")
driver = webdriver.Chrome('chromedriver', options=options) # Optional argument, if not specified will search path.
driver.get('https://mail.google.com/mail/u/0/#label/strongswan')
# time.sleep(5)
counter = 1
failure = 0
while failure <= 10:
print("deleting page %s" % counter)
try:
if failure == 10:
driver.refresh()
try:
driver.switch_to.alert.accept()
except EX.NoAlertPresentException:
pass
WebDriverWait(driver, 30).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, 'div[role="button"][aria-label="Select"] [aria-checked="false"]'))
)
all_box = driver.find_element_by_css_selector('div[role="button"][aria-label="Select"]')
all_box.click()
delete_btn = driver.find_element_by_css_selector('div[role="button"][aria-label="Delete"]')
delete_btn.click()
failure = 0
print("page %s deleted" % counter)
counter += 1
except EX.ElementNotInteractableException as ex:
failure += 1
print("page %s deletion failed. retrying... (%s/3)" % (counter, failure))
time.sleep(1)
refresh_btn = driver.find_element_by_css_selector('div[role="button"][aria-label="Refresh"]')
refresh_btn.click()
# time.sleep(5) # Let the user actually see something!
# driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment