在激活了“切换设备"工具栏的情况下打开Chrome [英] Open Chrome with Toggle Device Toolbar Activated
问题描述
我正在Selenium中使用Java,并且我必须自动化一些测试,以及一些如何使用Chrome Headless和Mobile Emulation的需求.我知道如何使用"--auto-open-devtools-for-tabs"和"mobileEmulation"打开chrome,但是我需要在激活切换设备工具栏"的情况下打开它.此模式模拟触摸交互事件,用触摸代替点击.如何使用此模式启动Chrome? (我正在使用ChromeDriver v.2.358161)
I'm working with java in Selenium, and I have to automaticed some tests, some how needs use Chrome Headless and Mobile Emulation. I know how to open chrome with "--auto-open-devtools-for-tabs" and with "mobileEmulation", but i need to open it with Toggle Device Toolbar activated. This mode, emulate the touch interactions events, replacing the click with a touch. How can i do start Chrome wiht this mode? (I´m using ChromeDriver v.2.358161)
这是我的代码:
(...)
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Galaxy S5");
ChromeOptions headlessOptions = new ChromeOptions();
headlessOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, headlessOptions);
driver = new ChromeDriver(capabilities);
(...)
我必须添加什么新参数?
What new argument i must to add?
(我让机器人按了 Ctrl + shift + M ,但这不适用于Chrome Headless.)
(I made a robot press Ctrl+shift+M but this doesn´t works with Chrome Headless).
protected void pressModoResponsive() throws AWTException {
pressF12();
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
waitSleep(1);
robot.keyPress(KeyEvent.VK_M);
waitSleep(1);
robot.keyRelease(KeyEvent.VK_M);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
}
推荐答案
我有同样的问题. 我无法让WebDriver在硒中模拟移动设备.
I have the same problem. I couldn't make WebDriver simulate a mobile device in selenium.
解决方法是添加参数:
--auto-open-devtools-for-tabs
,然后将设备切换为移动设备,并保留会话为--user-data-dir
The workaround is being to add the argument:
--auto-open-devtools-for-tabs
, then switch the device to mobile and leave the session saved with--user-data-dir
这篇关于在激活了“切换设备"工具栏的情况下打开Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!