蟒蛇 + Selenium(Chrome):慢速计算机上的扩展超时
我正在尝试将扩展程序(Metamask)加载到 chrome 中以执行一些自动化操作。它在我的游戏级装备上工作得很好,但我的笔记本电脑以及我技术过时的家庭服务器电脑超时:
opt = webdriver.ChromeOptions() opt.binary_location = self.chrome_exe_location opt.add_argument('--log-level=3') opt.add_argument('--start-maximized') opt.add_experimental_option('excludeSwitches', ['启用日志记录']) opt.add_extension(os.path.join(os.getcwd(), '10.9.3_0.crx')) self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='')
回溯(最近一次调用最后一次):文件 “C:\OneDrive\CloudDesktop\Python\main.py”,第 968 行,位于 bot() 文件“C:\OneDrive\CloudDesktop\Python\main.py”,第 69 行,位于 初始化 self.chrome_initialize() 文件“C:\OneDrive\CloudDesktop\Python\main.py”,第 118 行,位于 chrome_初始化 self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='') 文件 “C:\ OneDrive \ CloudDesktop \ Python \ vEnv \ lib \ site-packages \ selenium \ webdriver \ chrome \ webdriver.py”, 第 70 行,在 init 中 super(WebDriver, self).init(DesiredCapability.CHROME['browserName'], "goog",
文件 “C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\chromium\webdriver.py”,第 93 行,init RemoteWebDriver.init( 文件 "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py", 第 269 行,在 init 中 self.start_session(功能,browser_profile) 文件“C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py”, 第 360 行,在 start_session 中 响应 = self.execute(Command.NEW_SESSION, 参数) 文件 "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py", 第425行,执行中 self.error_handler.check_response(response) 文件“C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, check_response 中的第 247 行 引发异常类(消息,屏幕,堆栈跟踪)selenium.common.exceptions.WebDriverException:消息:未知错误: 无法等待扩展后台页面加载: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html 来自超时:从渲染器接收消息超时:10.000
- Chrome 和 chromedriver 版本 98.0.4758.102 64 位,所有计算机上
- Python 版本 3.10.1(一台电脑工作,一台不工作)和 3.10.2(不工作) 工作)
- 操作系统:Win 10(不工作)和11(工作)所有更新的
- CPU:5600x(工作),Snapdragon 8cx(不工作),Intel Celeron J3455(不工作)
我猜这个超时发生是因为selenium不会等到扩展已满载或已传输。 .crx 的大小约为 18MB,我认为它运行的计算机大约需要 5 秒,其他计算机大约需要 30 秒。
我已经对 selenium 超时进行了修改,但我发现这是一个失败的原因,因为我真的可以在创建 selenium 对象后设置这些参数,这首先会导致此超时。
你们中有人知道硒如何让启动过程有更多时间吗?
感谢您的帮助!
I'm trying to load an extension(Metamask) into chrome to do some automated stuff. It works just fine on on my gaming grade rig, but both my laptop as well as my technical outdated homeserver pc timeout:
opt = webdriver.ChromeOptions() opt.binary_location = self.chrome_exe_location opt.add_argument('--log-level=3') opt.add_argument('--start-maximized') opt.add_experimental_option('excludeSwitches', ['enable-logging']) opt.add_extension(os.path.join(os.getcwd(), '10.9.3_0.crx')) self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='')
Traceback (most recent call last): File
"C:\OneDrive\CloudDesktop\Python\main.py", line 968, inbot() File "C:\OneDrive\CloudDesktop\Python\main.py", line 69, in
init
self.chrome_initialize() File "C:\OneDrive\CloudDesktop\Python\main.py", line 118, in
chrome_initialize
self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='') File
"C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\chrome\webdriver.py",
line 70, in init
super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
File
"C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in init
RemoteWebDriver.init( File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 269, in init
self.start_session(capabilities, browser_profile) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 360, in start_session
response = self.execute(Command.NEW_SESSION, parameters) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 425, in execute
self.error_handler.check_response(response) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 247, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error:
failed to wait for extension background page to load:
chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html
from timeout: Timed out receiving message from renderer: 10.000
- Chrome and chromedriver versions 98.0.4758.102 64bit on all computers
- Python versions 3.10.1(one pc working and one desn't) and 3.10.2(not
working) - OS: Win 10(none working) and 11(working) all updated
- CPU:5600x(working), Snapdragon 8cx(not working),Intel Celeron J3455(not working)
I guess this timeout occurs because selenium does not wait until the expansion is fully loaded or transferred. The .crx is about 18MB in size and I'd say the computer on which it's working takes about 5 secs and both other ones about 30 secs.
I already tinkered with selenium timeouts, but I found it's a lost cause, because I really can just set these parameters after the selenium object is created, which causes this timeout in the first place.
Does anyone of you guys know a way how selenium allows the startup process some more time?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Google Chrome 对 chromedriver 的官方支持中,有一些建议使用
options.add_experimental_option('extensionLoadTimeout', 60000)
。指定的时间以毫秒为单位,因此 60,000 对应于一分钟的超时。这解决了速度慢的电脑的超时问题。
In the official Google Chrome support for chromedriver, there were some suggestions to use
options.add_experimental_option('extensionLoadTimeout', 60000)
.The time specified is in milliseconds, so 60 thousand corresponds to a timeout of one minute. This fixes timeout problems for slow PCs.
我找到了一个解决方法:
在 Chrome 的正常使用实例中下载扩展程序。
chrome://version/ 复制配置文件路径
例如 C:\Users\pcuser\AppData\Local\Google\Chrome\User Data\Default
Python 代码:
I found a workaround:
Download extension in a normal use instance of chrome.
chrome://version/ copy profile path
e.g. C:\Users\pcuser\AppData\Local\Google\Chrome\User Data\Default
Python code: