chrome 驱动程序不会使用 python 保持最大化
chrome driver wont stay maximised using python
Chromedriver v88.0.4324.96 和 88.0.4324.27 使用 python 不会保持最大化。我的旧 groovy 代码仍然适用于相同的驱动程序(和选项),所以我去尝试操作这些 chrome 选项但没有成功:
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")
我看过
Python can't fullscreen in webdriver chrome after update to v.85
但是全屏的东西给出了相同的结果,.maximize_window()
函数一打开就杀死了 window :( 这似乎是一个流行的解决方案。
我也无法升级到最新的 chrome(政策)并查看发行说明问题 3690 可能是问题所在,但现在 https://peter.sh/experiments/chromium-command-line-switches/ 已关闭...
查看 chrome 驱动程序日志,我看到正在调整大小,但不是我做的:
[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'))
基本上每次截图都不要设置window位置
options.add_argument("start-maximized")
不适用于我的情况。
相反,调用 driver.maximize_window()
对我有用。
Chromedriver v88.0.4324.96 和 88.0.4324.27 使用 python 不会保持最大化。我的旧 groovy 代码仍然适用于相同的驱动程序(和选项),所以我去尝试操作这些 chrome 选项但没有成功:
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")
我看过
Python can't fullscreen in webdriver chrome after update to v.85
但是全屏的东西给出了相同的结果,.maximize_window()
函数一打开就杀死了 window :( 这似乎是一个流行的解决方案。
我也无法升级到最新的 chrome(政策)并查看发行说明问题 3690 可能是问题所在,但现在 https://peter.sh/experiments/chromium-command-line-switches/ 已关闭...
查看 chrome 驱动程序日志,我看到正在调整大小,但不是我做的:
[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'))
基本上每次截图都不要设置window位置
options.add_argument("start-maximized")
不适用于我的情况。
相反,调用 driver.maximize_window()
对我有用。