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