Advertisement
Arthurious

Untitled

May 19th, 2019
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. import time
  2. import random
  3. from selenium import webdriver
  4.  
  5. chromedriver = "C:/Users/woofe/Downloads/chromedriver_win32/chromedriver"
  6. driver = webdriver.Chrome(chromedriver)
  7.  
  8. link = 'https://docs.google.com/forms/d/e/1FAIpQLSd7EiSdvEcPsbRYDU5-6niPu6TNisS27murJEKCyX59EJ_1GQ/viewform'
  9. driver.get(link)
  10.  
  11. xps = '//*[@id="mG61Hd"]/div/div[2]/div[2]/div['
  12. xpm = ']/div/div[2]/div/content/div/div['
  13. xpe = ']/label/div/div[1]/div[3]/div'
  14. submit_xp = '//*[@id="mG61Hd"]/div/div[2]/div[3]/div/div/div/content/span'
  15. another_xp = '/html/body/div[1]/div[2]/div[1]/div[2]/div[3]/a'
  16. code = "//*[@id=\"mG61Hd\"]/div/div[2]/div[2]/div[6]/div/div[1]/div/div/div"
  17. maxnum = [4, 2, 2, 2, 3]  # number of choice for each questions
  18.  
  19. counter = 0
  20.  
  21. nqT = len(maxnum)
  22. while 1:
  23.     num_ans = []
  24.     for i in range(0, len(maxnum)):
  25.         num_ans.append(random.randint(1, maxnum[i]))
  26.     driver.get(link)
  27.     for i in range(1, nqT + 1):
  28.         x_p = xps + str(i) + xpm + str(num_ans[i - 1]) + xpe
  29.         d = driver.find_element_by_xpath(x_p)
  30.         d.click()
  31.         # time.sleep(random.randint(1,2))
  32.         # change the speed of clicking by reducing sleep time
  33.         time.sleep(0.5)
  34.  
  35.     raw_parse = driver.find_elements_by_class_name("freebirdFormviewerViewItemsItemItemTitle")
  36.     full_parse = raw_parse[5].text
  37.     parse_list = full_parse.split(" ")
  38.     required_string = parse_list[2]
  39.     form = driver.find_element_by_class_name("quantumWizTextinputPaperinputInput")
  40.     form.send_keys(required_string)
  41.     submit = driver.find_element_by_xpath(submit_xp)
  42.     submit.click()
  43.     counter = counter + 1
  44.     print(counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement