Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active May 28, 2017 12:29
Show Gist options
  • Save kurozumi/84e48bffa1f29157d2ede335ca950c9f to your computer and use it in GitHub Desktop.
Save kurozumi/84e48bffa1f29157d2ede335ca950c9f to your computer and use it in GitHub Desktop.
【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