Skip to content

Instantly share code, notes, and snippets.

@kungtotte
Last active April 17, 2016 20:26
Show Gist options
  • Save kungtotte/fd3d6c90c325a7e2dd16ed80d3dfd9e1 to your computer and use it in GitHub Desktop.
Save kungtotte/fd3d6c90c325a7e2dd16ed80d3dfd9e1 to your computer and use it in GitHub Desktop.
Selenium upload example
import glob
from os.path import abspath
from selenium import webdriver
def create_driver():
options = webdriver.ChromeOptions()
options.add_extension('adblockpluschrome-1.11.0.1591.crx')
driver = webdriver.Chrome(chrome_options=options)
return driver
def upload_file(driver, path):
url = "https://anonfiles.com/upload"
upload_field = '//*[@id="main_form"]/form/p[1]/input[1]'
submit_button = '//*[@id="main_form"]/form/p[1]/input[2]'
driver.get(url)
driver.find_element_by_xpath(upload_field).send_keys(path)
driver.find_element_by_xpath(submit_button).click()
driver = create_driver()
for filename in glob.glob('*.txt'):
upload_file(driver, abspath(unicode(filename, 'latin-1')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment