【问题标题】:Trying to close portable browser via selenium试图通过硒关闭便携式浏览器
【发布时间】:2021-09-20 06:17:23
【问题描述】:

我正在尝试通过 selenium 关闭便携式浏览器

我通过了--remote-debugging-port=9222,因为如果我没有通过它,那么程序就会卡在webdriver.Chrome() 的对象创建中。它将打开便携式浏览器,但不会加载 URL。

但在打开 URL 后,我想关闭浏览器,但 driver.quit() 对我不起作用。我尝试了其他一些关闭浏览器的方法,但它们都不起作用。

我想关闭这个程序打开的浏览器的特定实例,而不是其他打开的浏览器实例。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.binary_location = 'C:/Portable/GoogleChromePortable/GoogleChromePortable.exe'
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--profile-directory=Person 1")
driver = webdriver.Chrome(options=chrome_options,executable_path='C:/Portabl/chromedriver_win32/chromedriver.exe')
url = "https://www.google.com/"
driver.get(url)
driver.quit()

我正在使用:

selenium 3.141.0, windows 10, python 3.8.0, portable chrome version 93.0.4577.63 (32-bit)

【问题讨论】:

    标签: python-3.x selenium-webdriver browser python-webbrowser


    【解决方案1】:

    你的这份声明

    我通过了 --remote-debugging-port=9222 因为如果我不通过它 程序卡在 webdriver.Chrome() 的对象创建中

    不正确。 --remote-debugging-port=9222 看起来像是部署应用程序的端口号,并且您已使用 chrome 选项将它们发送到 browser object

    driver.quit()
    

    这通常应该有效,当它不起作用时是什么错误?

    另外,对于关闭单个实例,您可以这样做

    driver.close()
    

    看看有没有帮助。

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多