LoginSignup
0
3

More than 3 years have passed since last update.

Selenium WebDriverの稼働チェックをするお話

Last updated at Posted at 2019-03-29

SeleniumのWebDriver が 今動いているかどうかチェックするいい感じのメソッドがどうもないようなので、上手い方法ないかを検討。

とりあえず implicitly_wait(0) を応用してみる

from selenium import webdriver

def __init__(self, executable_path):
    self.executable_path = executable_path
    self.launch_driver()

def healthcheck_browser(self):
    try:
        # webdriverにWaitをいれる処理。デフォルト値0を入力し、
        # エラーが発生しないかをチェック
        self.driver.implicitly_wait(0)
    except Exception:
        # すでに quit されていれば エラー になるので再起動をかける
        print("The webdriver is not working.")
        launch_driver()
    else:
        print("The webdriver is now working.")

def launch_driver(self):
    self.driver = webdriver.Chrome(executable_path=self.executable_path)
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3