Skip to content

Instantly share code, notes, and snippets.

@kurozumi

kurozumi/event_quit.py

Last active May 28, 2017
Embed
What would you like to do?
【Python】Seleniumの終了前後にイベントを登録する方法
from selenium.webdriver import Firefox
from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
try:
class MyListener(AbstractEventListener):
def before_quit(self, driver):
"""
ドライバが終了する前の処理
"""
print("Before quit")
def after_quit(self, driver):
"""
ドライバが終了した後の処理
"""
print("After quit")
driver = Firefox()
ef_driver = EventFiringWebDriver(driver, MyListener())
ef_driver.get("https://a-zumi.net")
except Exceptio as e:
print(e)
finally:
ef_driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment