Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. """ This is a script made to automate all the entry methods, to see the supoorted entries look here:
  2. https://gleam.io/examples ( Gleam Example Campaigns ) right now there's no way to change the 'participant' """
  3.  
  4. from selenium import webdriver
  5. from selenium.webdriver.common.keys import Keys
  6. from selenium.common.exceptions import NoSuchElementException
  7. from selenium.common.exceptions import ElementNotVisibleException
  8.  
  9. from time import sleep
  10.  
  11. options = webdriver.ChromeOptions()
  12. options.add_argument("user-data-dir=C:\UsersHomeDesktopProjects")
  13. driver = webdriver.Chrome(chrome_options=options)
  14.  
  15. def entering_process(window_before, i):
  16. try:
  17. # Responsible for visit only part #
  18. driver.find_element_by_css_selector('#{} .btn-large'.format(i)).click()
  19. sleep(1)
  20. window_after = driver.window_handles[1]
  21. driver.switch_to.window(window_after)
  22. sleep(4)
  23. driver.close()
  24. driver.switch_to.window(window_before)
  25. except (ElementNotVisibleException, NoSuchElementException):
  26. try:
  27. # Responsible for the what username/quote you used part #
  28. username_quote = driver.find_element_by_xpath('//input[@class="ng-empty ng-invalid ng-invalid-required ng-dirty ng-valid-parse ng-touched"]')
  29. username_quote.click()
  30. username_quote.clear()
  31. username_quote.send_keys('Random Name/Quote')
  32. except (ElementNotVisibleException, NoSuchElementException):
  33. try:
  34. # Responsible for the blog post part #
  35. blog_post = driver.find_element_by_xpath('//input[@class="ng-valid ng-empty ng-valid-maxlength ng-dirty ng-valid-parse ng-touched]')
  36. blog_post.click()
  37. blog_post.clear()
  38. blog_post.send_keys('https://testing.googleblog.com/')
  39. except (ElementNotVisibleException, NoSuchElementException):
  40. try:
  41. # Responsible for the opinion part #
  42. opinion = driver.find_element_by_xpath('//textarea[@name="data"]')
  43. opinion.click()
  44. opinion.clear()
  45. opinion.send_keys('Random Opinion')
  46. except (ElementNotVisibleException, NoSuchElementException):
  47. try:
  48. # Responsible for the twitch subscribers part #
  49. driver.find_element_by_xpath("//*[contains(text(), 'Sorry, only subscribers of')]")
  50. driver.find_element_by_partial_link_text('Cancel').click()
  51. except (ElementNotVisibleException, NoSuchElementException):
  52. try:
  53. # Responsible for the view instagram part #
  54. driver.find_element_by_xpath('//img[@class="EmbeddedMediaImage"]')
  55. sleep(1)
  56. except (ElementNotVisibleException, NoSuchElementException):
  57. try:
  58. # Responsible for choose image part #
  59. driver.find_element_by_xpath('//a[@class="image ng-isolate-scope"]').click()
  60. except (ElementNotVisibleException, NoSuchElementException):
  61. try:
  62. # Responsible for checkbox list part #
  63. driver.find_element_by_xpath('//label[@class="radio ng-binding"]').click()
  64. except (ElementNotVisibleException, NoSuchElementException):
  65. try:
  66. # Responsible for other type of checkbox list part #
  67. driver.find_element_by_xpath('//label[@class="checkbox ng-binding"]').click()
  68. except (ElementNotVisibleException, NoSuchElementException):
  69. try:
  70. # Responsible for blog post dropdown part part #
  71. driver.find_element_by_xpath('//select[@ng-model="entryState.formData[entry_method.id]["blog"]"]').click()
  72. driver.find_element_by_xpath('//option[@label="Sem título"]').click()
  73. except (ElementNotVisibleException, NoSuchElementException):
  74. try:
  75. # Responsible for tweet with this hashtag part #
  76. driver.find_element_by_xpath('//span[@class="twitter-label"]').click()
  77. window_after = driver.window_handles[1]
  78. driver.switch_to.window(window_after)
  79. driver.find_element_by_xpath('//input[@value="Tweetar"]').click()
  80. driver.switch_to.window(window_before)
  81. driver.find_element_by_xpath('//a[@ng-click="showExtra(entry_method)"]').click()
  82. except (ElementNotVisibleException, NoSuchElementException):
  83. try:
  84. # Responsible for the pin this part #
  85. driver.find_element_by_xpath('//a[@data-pin-log="button_pinit"]').click()
  86. window_after = driver.window_handles[1]
  87. driver.switch_to.window(window_after)
  88. driver.find_element_by_xpath('//div[@data-test-id="BoardPickerSaveButton"]').click()
  89. driver.close()
  90. driver.switch_to.window(window_before)
  91. except (ElementNotVisibleException, NoSuchElementException):
  92. try:
  93. # Responsible for blog post dropdown part #
  94. driver.find_element_by_xpath('//a[@back-img="twitter.thumb | removeProtocol"]').click()
  95. except (ElementNotVisibleException, NoSuchElementException):
  96. try:
  97. # Responsible for the youtube watch part #
  98. driver.find_element_by_xpath('//iframe[@title="YouTube video player"]')
  99. driver.switch_to.frame(driver.find_element_by_xpath('//iframe[@class="cover-video youtube youtube-lazy-init"]'))
  100. driver.find_element_by_class_name('ytp-large-play-button').click()
  101. sleep(1)
  102. driver.find_element_by_class_name('ytp-play-button').click()
  103. ActionChains(driver).send_keys(Keys.END).perform()
  104. driver.switch_to_default_content()
  105. except (ElementNotVisibleException, NoSuchElementException):
  106. try:
  107. # Responsible for the share linkedin part #
  108. driver.find_element_by_xpath('//span[@id="li_ui_li_gen_1518887151266_0"]').click()
  109. driver.switch_to.window(window_after)
  110. driver.close()
  111. driver.switch_to.window(window_before)
  112. except (ElementNotVisibleException, NoSuchElementException):
  113. pass
  114.  
  115. finally: # Responsible for continue after all variables was checked #
  116. try:
  117. # Responsible for clicking the continue button #
  118. driver.find_element_by_xpath('//button[@ng-click="saveEntryDetails(entry_method)"]').click()
  119. except (ElementNotVisibleException, NoSuchElementException):
  120. try:
  121. # Responsible for clicking the second version of the continue button #
  122. driver.find_element_by_xpath('//button[@ng-click="videoWatched(entry_method)"]').click()
  123. except (ElementNotVisibleException, NoSuchElementException):
  124. try:
  125. # Responsible for clicking the arrow to close the box if the continue wasn't available #
  126. driver.find_element_by_xpath('//i[@class="fa fa-chevron-down"]').click()
  127. except (ElementNotVisibleException, NoSuchElementException):
  128. print('No other continue method available, better try to implement it')
  129. pass
  130.  
  131. def start_process():
  132. """ Start the process of entering the givewaways,
  133. filtering by variables and then executing the measures """
  134.  
  135. url = input('Enter the Gleam link: ')
  136.  
  137. driver.get(url)
  138.  
  139. try:
  140. # Check if there is the unlock entries warning #
  141. window_before = driver.window_handles[0]
  142. driver.find_element_by_xpath('//h3[@ng-if="!isReward()"]') # Unlock element #
  143. ids = driver.find_elements_by_class_name('entry-method')
  144. ids = [x.get_attribute('id') for x in ids]
  145.  
  146. for i in ids:
  147. driver.find_element_by_id(i).click()
  148. sleep(1)
  149. entering_process(window_before, i)
  150.  
  151. except (ElementNotVisibleException, NoSuchElementException):
  152. # Start the normal process if the unlock warning was not found or finished #
  153. window_before = driver.window_handles[0]
  154. ids = driver.find_elements_by_class_name('entry-method')
  155. ids = [x.get_attribute('id') for x in ids]
  156.  
  157. for i in ids:
  158. driver.find_element_by_id(i).click()
  159. sleep(1)
  160. entering_process(window_before, i)
  161.  
  162. if __name__ == "__main__":
  163. print('Starting')
  164. start_process()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement