我正在尝试使用 Python 和 selenium 打开一个简单的 chrome 实例。请在下面找到我的代码:
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)
我希望它在后台打开,即当我输入其他内容时,鼠标/光标焦点不应在打开后随机转到此自动 chrome 实例。
限制:请注意以下限制:
- 我不能使用“--headless”
- 我不能使用 phantomJS
- 我不能使用 PyVirtualDisplay,因为代码(exe 文件)最终将部署在 Windows 机器上供最终用户使用。
还有其他方法可以将此 chrome 实例推到后台吗?谢谢