一段时间没有活动后,如何禁用Selenium chrome驱动程序的自动关闭操作? [英] How to disable selenium chrome driver's auto closed action after some time without activity?
问题描述
我使用硒RemoteWebdriver连接到远程集线器.
I used selenium RemoteWebdriver to connection to remote hubs.
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')
如果一段时间没有任何活动,则该会话将自动关闭.
If there are no activities for some times, the session would be auto closed.
>>> driver.title
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in title
resp = self.execute(Command.GET_TITLE)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: No active session with ID 227c970ff0d633fce0e68c57c40e70b7
这是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分钟内自动关闭无活动会话. 我想知道如何在没有活动的情况下禁用自动关闭操作吗?
So I guess the chrome driver will auto closed the no-activity session in 30 minutes. I want to know how I can disable the auto-closed action with no activity?
推荐答案
我从
-sessionTimeout
-sessionTimeout 指定在服务器自动终止最近X秒钟内没有任何活动的会话之前的超时.然后将释放测试插槽,以供其他测试使用.这通常用于照顾客户端崩溃.对于网格中心/节点角色,还必须设置cleanUpCycle.如果未指定节点,则将使用集线器值. 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秒,与预期的日志相同. The timeout is indeed 1800s, it is the same the log expected. 然后我发现了另一个有关的问题问题这个. And then I found another question about this. 我对Java不熟悉.
我使用 I am not familiar with java.
I used 这是我的docker-compose文件: This is my docker-compose file: 大约一年的超时时间. 这篇关于一段时间没有活动后,如何禁用Selenium chrome驱动程序的自动关闭操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
java -jar /opt/selenium/selenium-server-standalone.jar -sessionTimeout 31536000
selenium/standalone-chrome-debug:3.141.59-mercury
泊坞窗映像运行chromdriver.
因此,如果您还使用docker,则可以在运行docker时设置env.selenium/standalone-chrome-debug:3.141.59-mercury
docker image to run the chromdriver.
So if you also use docker, you can set env when running docker.chrome:
image: selenium/standalone-chrome-debug:3.141.59-mercury
volumes:
- /dev/shm:/dev/shm
ports:
- 127.0.0.1:4444:4444
- 127.0.0.1:5900:5900
environment:
- SE_OPTS=-sessionTimeout 31536000