如何使用镀铬选项将无头镀铬的窗口大小设置为全屏? [英] How to set window-size to fullscreen for headless-chrome using chrome options?

查看:70
本文介绍了如何使用镀铬选项将无头镀铬的窗口大小设置为全屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行UI测试时,出现一个错误,提示硒不支持chromedriver自动调整窗口大小,导致测试失败.

When executing UI tests, I get an error that selenium doesn't support automatic window resizing for chromedriver, which results in tests failing.

是否可以使用 headless-chrome 的chrome-options设置此设置?

Is there a way to set this using chrome-options for headless-chrome ?

我尝试了以下方法,

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");

此外,用-start-fullscreen" -kiosk" 替换"---- start-maximized" .

但是上述方法都不适合我,唯一适用于我的选项是-window-size = width,height" .

But none of the above worked for me, the only option that works for me is "--window-size=width,height".

我不想对宽度和高度的值进行硬编码,有什么办法可以设置全屏?

I do not want to hard-code values for width and height, is there some way I can do this to set fullscreen ?

推荐答案

问题是,无头模式适用于没有屏幕的计算机,因此即使您没有屏幕,也无法确定屏幕的大小有一个.唯一的方法是使用--window-size将信息传递给浏览器.

The problem is that headless mode is meant to be used on computers without screens, so there's no way for it to figure out what size your screen is even if you have one. The only way is for you to pass that information to the browser with --window-size.

在所有平台上,无头模式下的默认窗口大小和显示大小均为800x600.

The default window size and display size in headless mode is 800x600 on all platforms.

因此,最大化的窗口大小不适用于无头无铬镶边,需要时由用户明确设置.

So the maximized window size is not applicable for chrome-headless and needs to be explicitly set by users, if required.

这篇关于如何使用镀铬选项将无头镀铬的窗口大小设置为全屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆