Skip to content

Instantly share code, notes, and snippets.

@Daworks
Forked from allieus/README.md
Created October 8, 2018 08:08
Show Gist options
  • Select an option

  • Save Daworks/c18c90db437a46f4e8f42463833670d4 to your computer and use it in GitHub Desktop.

Select an option

Save Daworks/c18c90db437a46f4e8f42463833670d4 to your computer and use it in GitHub Desktop.
selenium 을 통한 홈택스 자동화 심플 예제

Download, Internet Explorer Driver Server

필요조건

  • 인터넷 옵션/보안에서 모든 존 (인터넷, 로컬인터넷, 신뢰사이트, 제한사이트) 에 대해 보호모드 사용 끄기
'''
홈택스 Internet Explorer 11 Selenium 자동화
필요조건
- 인터넷 옵션/보안에서 모든 존 (인터넷, 로컬인터넷, 신뢰사이트, 제한사이트) 에 대해 보호모드 사용 끄기
'''
from collections import Iterable
import time
from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException, TimeoutException, UnexpectedAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
class IEBrowser:
def __init__(self):
self.driver = webdriver.Ie('./IEDriverServer_2.53.1_x64.exe') # FIXME: Fixed Driver Path
def visit(self, url):
self.driver.get(url)
return self
def click(self, element_id):
self.driver.find_element_by_id(element_id).click()
return self
def wait(self, element_id, timeout):
expected = EC.presence_of_element_located((By.ID, element_id))
WebDriverWait(self.driver, timeout).until(expected)
return self
def switch_to_frame(self, frame_id):
self.driver.switch_to_frame(frame_id)
return self
def alert_dismiss(self):
try:
self.driver.switch_to_alert().dismiss()
except NoAlertPresentException as e:
print(e)
return self
def quit(self):
self.driver.quit()
return self
def main():
browser = IEBrowser()
browser.visit("https://www.hometax.go.kr")
try:
print("waiting group1300 ...")
browser.wait('group1300', 5)
print("click group_1300")
browser.click('group1300')
try:
browser.wait('txppIframe', 3)
except UnexpectedAlertPresentException as e:
print(e)
browser.alert_dismiss().alert_dismiss()
browser.switch_to_frame('txppIframe').click('a_0111060000')
print("3초 뒤에 브라우저를 닫습니다.")
time.sleep(3)
finally:
browser.quit()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment