Skip to content

Instantly share code, notes, and snippets.

@gannebamm
Created September 11, 2019 14:51
Show Gist options
  • Save gannebamm/a3fe71ba614f4338fb2a3b85e9924d5e to your computer and use it in GitHub Desktop.
Save gannebamm/a3fe71ba614f4338fb2a3b85e9924d5e to your computer and use it in GitHub Desktop.
uploading files to a GeoNode instance by using selenium as webdriver
from selenium import webdriver
import time
import os
# must use chromedriver, since others do not interact
# with hidden elements (such as the multi upload input-field)
PATH_TO_DRIVER = "D:\\chromedriver.exe"
# set folder with files to upload
FOLDER = "D:\\temp\\upload\\"
# fill files to upload (shp,tif, including xml allowed)
FILES = []
for f in os.listdir(FOLDER):
FILES.append(os.path.join(FOLDER, f))
# autoupload will be used for automated uploads
# the layers will not be visible by anyone except autoupload user
# and superusers
USER = os.environ.get("GEONODE_USER", "test")
PASS = os.environ.get("GEONODE_PASS", "test")
# the geonode site to upload to
SITE = 'https://some.geonode.org'
driver = webdriver.Chrome(executable_path=PATH_TO_DRIVER)
driver.get(SITE + '/account/login/?next=/')
time.sleep(0.5)
driver.find_element_by_id('id_login').send_keys(USER)
driver.find_element_by_id('id_password').send_keys(PASS)
time.sleep(0.5)
submit_button = driver.find_element_by_css_selector('html body div#wrap div.container div.row div.col-md-8 form button.btn.btn-primary')
submit_button.click()
time.sleep(1)
driver.get(SITE + '/layers/upload')
file_input = driver.find_element_by_id('file-input')
for f in FILES:
file_input.send_keys(f)
time.sleep(0.5)
# the layer will not be visible by anyone except test user
# and superusers
driver.find_element_by_id('perms_view_anyone').click()
time.sleep(0.5)
driver.find_element_by_id('upload-button').click()
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment