我如何隐藏命令提示符窗口时,Selenium启动谷歌浏览器便携式?

ioekq8ef  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(330)

我的电脑上安装了Chrome浏览器113版,我的机器上也保存了Google Chrome便携版114。我编写了Selenium来启动Chrome便携版,它工作起来没有问题,但它也打开了命令提示符窗口。
image is here
我的代码:

  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.chrome.service import Service
  4. from selenium.webdriver.support.wait import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import subprocess
  7. import os
  8. current_directory = os.path.dirname(os.path.abspath(__file__))
  9. driver_path = os.path.join(current_directory, "chromedriver.exe")
  10. chrome_path = os.path.join(current_directory, "GoogleChromePortable_114.0.5735.91\GoogleChromePortable.exe")
  11. profile_path = os.path.join(current_directory, "GoogleChromePortable_114.0.5735.91\Data\profile\Default")
  12. chrome_options = webdriver.ChromeOptions()
  13. chrome_options.add_argument("--remote-debugging-port=9222")
  14. chrome_options.add_argument("--user-data-dir=" + profile_path)
  15. chrome_service = Service(driver_path)
  16. chrome_service.creation_flags = subprocess.CREATE_NO_WINDOW
  17. chrome_options.binary_location = chrome_path
  18. browser = webdriver.Chrome(options=chrome_options,service=chrome_service)

有办法隐藏命令提示符窗口吗?我已经尝试了'chrome_service.creation_flags = subprocess.CREATE_NO_WINDOWS',但没有运气。

rvpgvaaj

rvpgvaaj1#

尝试使用您的chrome_serviceHideCommandPromptWindow属性(C#中),可以在python中查找对应的名称。

  1. chrome_service.HideCommandPromptWindow =true

你可以参考我的repo TextForCtext代码。

相关问题