如何在chrome中默认启用设备仿真模式(设备模式)

Posted

技术标签:

【中文标题】如何在chrome中默认启用设备仿真模式(设备模式)【英文标题】:How to enable device emulation mode (device mode) in chrome by default 【发布时间】:2017-04-22 02:20:43 【问题描述】:

如何在没有在开发工具中手动启用的情况下,通过设备模式模拟(将鼠标事件模拟为触摸屏事件)运行 chrome?

最好带有标志更改或运行时参数更改。

【问题讨论】:

【参考方案1】:
public static void main(String[] args) 
    System.setProperty("webdriver.chrome.driver", "/Users/guolei/tmp/chromedriver");
    Map<String, String> mobileEmulation = new HashMap<>();

    mobileEmulation.put("deviceName", "iPhone 6");

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    chromeOptions.addArguments("start-maximized");

    WebDriver driver = new ChromeDriver(chromeOptions);

    driver.get("http://m.taoche.com/");

【讨论】:

以上是关于如何在chrome中默认启用设备仿真模式(设备模式)的主要内容,如果未能解决你的问题,请参考以下文章