python - chrome驱动程序不会使用python保持最大化
问题描述
使用 python 的 Chromedriver v88.0.4324.96 和 88.0.4324.27 不会保持最大化。我的旧 groovy 代码仍然可以使用相同的驱动程序(和选项),所以我去尝试操作这些 chromeoptions,但没有成功:
options.add_argument("--window-size=1920x1080")
options.add_argument("--start-maximized")
options.add_argument('--disable-extensions')
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_argument("--disable-features=NetworkService")
options.add_argument("--disable-features=VizDisplayCompositor")
options.add_argument("--no-sandbox")
options.add_argument("--useAutomationExtension=false")
在更新到 v.85 后,我已经查看了
Python can't fullscreen in webdriver chrome
但是全屏的东西给出了相同的结果,并且该.maximize_window()
函数在窗口打开后立即杀死它:(这似乎是一个流行的解决方案。
我也无法升级到最新的 chrome(策略)并且查看发行说明问题 3690 可能是问题,但现在https://peter.sh/experiments/chromium-command-line-switches/已关闭...
查看 chromedriver 日志,我看到调整大小发生了,但不是来自我:
[1614679235.268][INFO]: Waiting for pending navigations...
[1614679235.268][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=144) 0C0CC2C41CA4BE07557A5F9CB5CFFFEC {
"expression": "1"
}
[1614679235.269][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=144) 0C0CC2C41CA4BE07557A5F9CB5CFFFEC {
"result": {
"description": "1",
"type": "number",
"value": 1
}
}
[1614679235.269][INFO]: Done waiting for pending navigations. Status: ok
[1614679235.269][DEBUG]: DevTools WebSocket Command: Browser.getWindowForTarget (id=6) browser {
"targetId": "0C0CC2C41CA4BE07557A5F9CB5CFFFEC"
}
[1614679235.269][DEBUG]: DevTools WebSocket Response: Browser.getWindowForTarget (id=6) browser {
"bounds": {
"height": 935,
"left": 10,
"top": 10,
"width": 1920,
"windowState": "normal"
},
"windowId": 1
}
解决方案
每次都是截图
s = lambda x: self.driver.execute_script('return document.body.parentNode.scroll' + x) self.driver.set_window_size(s('Width'), s('Height'))
基本上,每次截图时不要设置窗口位置
推荐阅读
- javascript - 使用 Promise.all 删除所有 id
- c - 打包位并读取它们 - C
- html - 我的复选框或单选按钮没有正确对齐?
- vb6 - 如何在任何地方获取 VBScript 的返回值到自动化?
- ios - 点击时无法为选定的集合视图单元格设置动画
- reactjs - 在酶模拟函数中传递完整的“事件”对象
- python - Conv2d和padding的值
- java - 我正在使用 Spring Boot REST API 应用程序,当多个用户调用此 API 时,该应用程序具有 POST 调用我面临数据不一致
- ios - UIImageView在动画的时候回到原来的位置
- c++ - 为什么编译器会跳过我的 while 语句?