I am trying to open a simple chrome instance using Python and selenium. Please find my code below:
import time, datetime, sys, os
start_time = time.time()
from datetime import datetime
os.system("cls")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
CHROME_PATH = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
CHROMEDRIVER_PATH = 'C:\\Users\\'+userID+'\\'+filename+'\\chromedriver.exe'
WINDOW_SIZE = "1920,1080"
chrome_options = Options()
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.add_argument("disable-gpu")
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--disable-notifications")
chrome_options.binary_location = CHROME_PATH
browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=chrome_options)
time.sleep(1)
browser.get("https://www.google.com")
os.system("cls")
time.sleep(2)
I would like this to open in the background ie when I am typing something else the mouse/cursor focus should not randomly go to this automated chrome instance once it opens.
Limitations: Please note the below limitations:
- I can not use "--headless"
- I can not use phantomJS
- I can not use PyVirtualDisplay as the code(exe file) will eventually be deployed on windows machines for the end-users.
Would there be any other way to push this chrome instance to the background? Thanks