Skip to content

Instantly share code, notes, and snippets.

@turtlemonvh
Created September 19, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turtlemonvh/363b952335100cd9f2395717d9866616 to your computer and use it in GitHub Desktop.
Save turtlemonvh/363b952335100cd9f2395717d9866616 to your computer and use it in GitHub Desktop.
Selenium survey voting

Selenium tests

Experiments with selenium to vote on a SurveyMonkey survey on OSX. Uses PhantomJS. Headless chrome may be a better option now.

You should have

  • java installed (can download dmg from oracle)
  • phantomjs installed: http://phantomjs.org/download.html
    • it needs to be on your path
    • assuming you downloaded and unzipped version 2.1.1 into the current directory, you can use . setpath.sh to fix your path
    • alternatively, you could just put the binary on your path
  • pip install selenium
  • geckodriver on your path (for firefox: https://github.com/mozilla/geckodriver/releases)
    • it can be in this directory

You don't need the selenium server itself (http://www.seleniumhq.org/download/).

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
survey_id = "XXXX" # replace with id of your survey
response = "honeypot"
for i in range(10):
#driver = webdriver.Firefox()
driver = webdriver.PhantomJS()
driver.get("https://www.surveymonkey.com/r/%s" % (survey_id))
text_input = driver.find_element_by_css_selector("div.questions div.other-answer-container input")
text_input.clear()
text_input.send_keys(response)
print("Sent keys", i)
time.sleep(3)
submit_btn = driver.find_element_by_css_selector("div.survey-submit-actions button")
submit_btn.click()
print("Clicked", i)
time.sleep(3)
driver.quit()
print("Exited", i)
time.sleep(3)
PATH=$PATH:./phantomjs-2.1.1-macosx/bin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment