# SSAFY automation with Selenium
It's really annoying to do this everyday. Should have done this months ago but here we go.
# Preparation
pip install selenium
Download chromedriver
Place it at C:\Program Files (x86)
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
1
2
3
2
3
# Execution
# Opening browser
driver.get("http://edu.ssafy.com/")
1
# Accessing HTML
id = driver.find_element_by_id("userId")
pwd = driver.find_element_by_id("userPwd")
1
2
2
.text
to access inner text
# Wait until present
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.CLASS_NAME, "pop-event-close"))
)
print(element)
except:
print("error 1")
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
1 2 5 7 9
# Typing
# Environment Variable
pip install python-dotenv
From dotenv import load_dotenv
load_dotenv()
import os
token = os.environ.get("api-token")
1
2
3
4
2
3
4
api-token = "abcdef_123456"
1