Created
May 1, 2021 20:10
-
-
Save satra/64f12fe4830c9632ab1933e40c85a3d9 to your computer and use it in GitHub Desktop.
Login to DANDI Web UI using selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
import chromedriver_binary | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.common.exceptions import TimeoutException | |
from getpass import getpass | |
class DANDILogin: | |
"""Selenium login using DANDI Web UI | |
Adapted from: https://github.com/stayhigh/github-login-selenium/blob/master/github_login.py | |
""" | |
def __init__(self): | |
from selenium.webdriver.chrome.options import Options | |
options = Options() | |
# options.headless = True | |
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser' | |
self.driver = webdriver.Chrome(options=options) | |
self.driver.implicitly_wait(10) | |
self.base_url = "https://github.com/" | |
self.dandi_url = "https://gui.dandiarchive.org/" | |
def github_login(self, github_account, github_passwd): | |
driver = self.driver | |
driver.get(self.base_url + "/login") | |
driver.find_element_by_id("login_field").clear() | |
driver.find_element_by_id("login_field").send_keys(github_account) | |
driver.find_element_by_id("password").clear() | |
driver.find_element_by_id("password").send_keys(github_passwd) | |
driver.find_element_by_name("commit").click() | |
def dandi_login(self): | |
driver = self.driver | |
driver.get(self.dandi_url) | |
login_el = driver.find_elements_by_class_name('mx-1').pop() | |
login_el.click() | |
try: | |
element = WebDriverWait(driver, 5).until( | |
EC.presence_of_element_located((By.NAME, "allow")) | |
) | |
except TimeoutException: | |
pass | |
else: | |
element.click() | |
def login(self, github_account, github_passwd=None): | |
if github_passwd is None: | |
github_passwd = getpass("input your github password:") | |
self.github_login(github_account, github_passwd) | |
self.dandi_login() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment