-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selenium.py
69 lines (49 loc) · 1.85 KB
/
Selenium.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
a = raw_input("Enter number of mails to be deleted in multiple of 50 ")
a = int(a)
# For eg 250 is entered
a /= 50
email = raw_input("Enter your email ")
password = raw_input("Enter your password")
# Download chrome driver from https://sites.google.com/a/chromium.org/chromedriver/downloads
# Replace with your path tot he driver
driver = webdriver.Chrome('/Users/samarthgupta/Downloads/chromedriver')
driver.get("https://mail.google.com/")
assert "Gmail" in driver.title
# Enter email
elem = driver.find_element_by_xpath('//*[@id="identifierId"]')
elem.clear()
elem.send_keys(email)
# Click next
elem = driver.find_element_by_xpath('//*[@id="identifierNext"]')
elem.send_keys(Keys.RETURN)
# Enter password
# Page takes time to load therefore using wait
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.NAME, "password"))
)
elem = driver.find_element_by_name("password")
elem.send_keys(password)
# Click next
elem = driver.find_element_by_xpath('//*[@id="passwordNext"]')
elem.send_keys(Keys.RETURN)
# Page takes time to load therefore using wait
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.XPATH, '//*[@id=":2p"]/div[5]'))
)
driver.find_element_by_xpath('//*[@id=":2p"]/div[5]').click()
for i in range(a):
print (i)
if i > 0:
time.sleep(5)
print("Wait over ie select all button visible ")
driver.find_element_by_css_selector('div.T-Jo-auh').click()
print("Wait over ie delete all button visible ")
driver.find_element_by_css_selector('div.ar9.T-I-J3.J-J5-Ji').click()
assert "No results found." not in driver.page_source
driver.close()