我正在尝试通过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)
发布于 2021-09-20 06:25:01
你的这份声明
我通过了--远程调试-端口=9222,因为如果我不通过它,程序就会卡在webdriver.Chrome()的对象创建中。
是不对的--remote-debugging-port=9222
看起来像是部署应用程序的端口号,并且使用了chrome选项将它们发送到browser object
。
driver.quit()
这通常应该是有效的,当它不起作用时,错误是什么?
另外,对于关闭单个实例,您可以这样做。
driver.close()
看看这是否有帮助。
https://stackoverflow.com/questions/69249851
复制相似问题