Infernale

Populate Google Form

Aug 22nd, 2020 (edited)
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import random
  2. import string
  3. import time
  4. from selenium import webdriver
  5.  
  6. def get_random_letters():
  7.     names = string.ascii_letters
  8.     return random.choice(names).upper() + random.choice(names).upper()
  9.  
  10. def fill_personal_data():
  11.     text_input = driver.find_elements_by_class_name('quantumWizTextinputPaperinputInput.exportInput')
  12.  
  13.     # Fill Name Input
  14.     name = text_input[0]
  15.     name.send_keys(get_random_letters())
  16.  
  17.     university = text_input[2]
  18.     univ_names = ['Universitas Tarumanagara', 'BINUS University', 'Trisakti School of Management', 'Atma Jaya']
  19.     university.send_keys(random.choice(univ_names))
  20.  
  21. def choose_random_radios():
  22.     radio_student = driver.find_element_by_id('i13')
  23.     radio_assistant = driver.find_element_by_id('i16')
  24.  
  25.     is_student = random.randrange(5)
  26.     if is_student <= 3:
  27.         radio_student.click()
  28.     else:
  29.         radio_assistant.click()
  30.  
  31. def choose_random_traits(questions):
  32.     radio = driver.find_elements_by_class_name('appsMaterialWizToggleRadiogroupEl')
  33.    
  34.     for i in range(questions):
  35.         choosen = random.choices(population=[0, 1, 2, 3], weights=[0.1, 0.1, 0.4, 0.4])
  36.         radio[i*3 + choosen[0] + i].click()
  37.  
  38.  
  39.  
  40. num_of_times = 10
  41. driver = webdriver.Edge('C:\msedgedriver.exe')
  42.  
  43. for i in range(num_of_times):
  44.     driver.get('https://docs.google.com/forms/d/e/1FAIpQLSezymJcusO6GfRKg-o2xVrcjRqhyU9xWYWl4y0kfaAZDNBNkQ/formResponse')
  45.  
  46.     firstPageSubmit = driver.find_element_by_css_selector("span.quantumWizButtonPaperbuttonLabel.exportLabel")
  47.     firstPageSubmit.click()
  48.  
  49.     fill_personal_data()
  50.     choose_random_radios()
  51.  
  52.     driver.find_elements_by_css_selector('span.quantumWizButtonPaperbuttonLabel.exportLabel')[2].click()
  53.  
  54.     choose_random_traits(4)
  55.  
  56.     driver.find_elements_by_css_selector('span.quantumWizButtonPaperbuttonLabel.exportLabel')[1].click()
  57.  
  58.     choose_random_traits(5)
  59.  
  60.     driver.find_elements_by_css_selector('span.quantumWizButtonPaperbuttonLabel.exportLabel')[1].click()
  61.  
Add Comment
Please, Sign In to add comment