如何在一段时间没有活动后禁用selenium chrome驱动程序的自动关闭操作?

2024-04-20 02:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用selenium RemoteWebdriver连接到远程集线器。在

options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36")
driver = webdriver.Remote('http://127.0.0.1:4444/wh/hub', desired_capabilities=options.to_capabilities())
driver.get('https://example.com')

如果有一段时间没有活动,会话将自动关闭。在

^{pr2}$

以下是selenium/standalone-chrome-debug:3.141.59-mercury的登录容器:

chrome_1_9da7c6574f3b | 04:27:09.199 INFO [ActiveSessionFactory.apply] - Capabilities are: {
chrome_1_9da7c6574f3b |   "browserName": "chrome",
chrome_1_9da7c6574f3b |   "goog:chromeOptions": {
chrome_1_9da7c6574f3b |     "extensions": [
chrome_1_9da7c6574f3b |     ],
chrome_1_9da7c6574f3b |     "args": [
chrome_1_9da7c6574f3b |       "window-size=1920,1080",
chrome_1_9da7c6574f3b |       "user-agent=Mozilla\u002f5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit\u002f537.36 (KHTML, like Gecko) Chrome\u002f73.0.3683.86 Safari\u002f537.36"
chrome_1_9da7c6574f3b |     ]
chrome_1_9da7c6574f3b |   },
chrome_1_9da7c6574f3b |   "version": ""
chrome_1_9da7c6574f3b | }
chrome_1_9da7c6574f3b | 04:27:09.200 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
chrome_1_9da7c6574f3b | Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 15565
chrome_1_9da7c6574f3b | Only local connections are allowed.
chrome_1_9da7c6574f3b | Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
chrome_1_9da7c6574f3b | 04:27:09.809 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
chrome_1_9da7c6574f3b | 04:27:09.822 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 227c970ff0d633fce0e68c57c40e70b7 (org.openqa.selenium.chrome.ChromeDriverService)

----: No activities here:-----


chrome_1_9da7c6574f3b | 04:59:04.125 INFO [ActiveSessions$1.onStop] - Removing session 227c970ff0d633fce0e68c57c40e70b7 (org.openqa.selenium.chrome.ChromeDriverService)

所以我想chrome驱动程序会在30分钟内自动关闭无活动会话。 我想知道如何在没有活动的情况下禁用自动关闭操作?在


Tags: orginfoaddmozillasizesessionseleniumchrome
1条回答
网友
1楼 · 发布于 2024-04-20 02:21:20

我从code here找到了线索

-sessionTimeout

Specifies the timeout before the server automatically kills a session that hasn't had any activity in the last X seconds. The test slot will then be released for another test to use. This is typically used to take care of client crashes. For grid hub/node roles, cleanUpCycle must also be set. If a node does not specify it, the hub value will be used.

超时确实是1800秒,与预期的日志相同。在

然后我发现了另一个关于这个的question。在

java -jar /opt/selenium/selenium-server-standalone.jar -sessionTimeout 31536000

我不熟悉java。 我使用selenium/standalone-chrome-debug:3.141.59-mercurydocker image来运行chromdriver。 所以如果你同时使用docker,你可以在运行docker时设置env。在

这是我的docker compose文件:

^{pr2}$

大约是一年的暂停时间。在

相关问题 更多 >