我的电脑上安装了Chrome浏览器113版,我的机器上也保存了Google Chrome便携版114。我编写了Selenium来启动Chrome便携版,它工作起来没有问题,但它也打开了命令提示符窗口。
image is here
我的代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import subprocess
import os
current_directory = os.path.dirname(os.path.abspath(__file__))
driver_path = os.path.join(current_directory, "chromedriver.exe")
chrome_path = os.path.join(current_directory, "GoogleChromePortable_114.0.5735.91\GoogleChromePortable.exe")
profile_path = os.path.join(current_directory, "GoogleChromePortable_114.0.5735.91\Data\profile\Default")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--user-data-dir=" + profile_path)
chrome_service = Service(driver_path)
chrome_service.creation_flags = subprocess.CREATE_NO_WINDOW
chrome_options.binary_location = chrome_path
browser = webdriver.Chrome(options=chrome_options,service=chrome_service)
有办法隐藏命令提示符窗口吗?我已经尝试了'chrome_service.creation_flags = subprocess.CREATE_NO_WINDOWS',但没有运气。
1条答案
按热度按时间rvpgvaaj1#
尝试使用您的chrome_service的HideCommandPromptWindow属性(C#中),可以在python中查找对应的名称。
你可以参考我的repo TextForCtext代码。