· 7 years ago · Apr 15, 2019, 08:12 AM
1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3import random
4import time
5
6chrome_options = webdriver.ChromeOptions()
7chrome_options.add_argument('--incognito')
8
9driver = webdriver.Chrome(options=chrome_options)
10driver.get('https://www.google.com/search?q=gmail')
11
12results = driver.find_elements_by_class_name("LC20lb")
13results[0].click()
14
15create_new_acc = driver.find_element_by_xpath("//a[@title='Създаване на профил']")
16
17window_before = driver.window_handles[0]
18create_new_acc.click()
19window_after = driver.window_handles[1]
20driver.switch_to.window(window_after)
21
22with open("Names.txt") as file:
23 names = file.readlines()
24
25names = [x.strip() for x in names]
26
27secure_random = random.SystemRandom()
28
29firstName = secure_random.choice(names)
30
31input_first_name = driver.find_element_by_id('firstName')
32input_first_name.send_keys(firstName)
33time.sleep(3)
34
35lastName = secure_random.choice(names)
36
37input_last_name = driver.find_element_by_id('lastName')
38input_first_name.click()
39input_last_name.send_keys(lastName)
40
41time.sleep(4)
42
43username = str(60191)
44input_username = driver.find_element_by_id('username')
45#input_username.click()
46input_username.send_keys(username)
47time.sleep(5)
48
49username = input_username.get_attribute('value')
50
51password=""
52
53for name in random.sample(names, 5):
54 for character in random.sample(name, 2):
55 password+=character
56
57input_password = driver.find_element_by_xpath("//input[@name='Passwd']")
58input_password.click()
59input_password.send_keys(password)
60time.sleep(5)
61
62input_password = driver.find_element_by_xpath("//input[@name='ConfirmPasswd']")
63input_password.click()
64input_password.send_keys(password)
65time.sleep(3)
66
67print()
68print("Hello, " + firstName + " " + lastName + " !")
69print()
70print("Your usr: " + username + "@gmail.com")
71print("Your pass: " + password)
72
73window_before_submit = driver.window_handles[0]
74driver.find_element_by_id('accountDetailsNext').click()
75window_after_submit = driver.window_handles[1]
76driver.switch_to.window(window_after_submit)