Jack Wong
Jack Wong

Reputation: 89

How to check if chromedriver exist or running?

I am using 3rd party software to create a fancy application GUI with several buttons.

Each buttons will execute different .py file/.exe file. For instance:-

btnYahoo = execute yahoo.py/yahoo.exe

btnGoogle = execute google.py/google.exe

So inside both py scripts is using chromedriver to launch Chrome Browser and redirect to specific URLs

google.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path=r'chromedriver.exe')
driver.get("https://www.google.com")

yahoo.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path=r'chromedriver.exe')
driver.get("https://malaysia.yahoo.com/?p=us")

So if I execute both scripts above, it will launch 2 chrome browser.

Therefore, my concern is how can I check is webdriver.Chrome is running?

If so, then assign the webdriver.Chrome to a variable, so that I can open new tab and do further automate script progress.

For example of expected result:

  1. Execute google.py - A new chrome browser is open and redirect to www.google.com

  2. Execute yahoo.py - If webdriver.Chrome is executed/existed, then assign the browser to driver variable. Else launch new browser

Thanks for advance information.

Upvotes: 6

Views: 9003

Answers (1)

Happy John
Happy John

Reputation: 67

I was able to do so by checking if driver.session_id was None.

Upvotes: 1

Related Questions