在我基于 selenium 的测试中,我将窗口大小设置为 400(w) 719(h) 以创建 400x640 的内部视口大小。我的大多数测试都是基于该尺寸,尽管有些测试使用其他尺寸。
Dimension size = new Dimension(400, 719);
driver.manage().window().setSize(size);
最新版本的 Chrome 无法将窗口大小设置为 400 像素宽度,而是生成的窗口宽度约为 500 像素(尽管有所不同)。
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2639 https://bugs.chromium.org/p/chromedriver/issues/detail?id=2639(错误,声称已修复,但似乎没有)
所以我想设置内部视口大小。
如何在 selenium/chrome webdriver 中执行此操作?
你可以看看chromedriver移动仿真 http://chromedriver.chromium.org/mobile-emulation.
正如那里提到的,
java例子
Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", 360);
deviceMetrics.put("height", 640);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)