【问题标题】:Chrome 32 - control emulation via JS or webdriverChrome 32 - 通过 JS 或 webdriver 控制仿真
【发布时间】:2014-02-10 17:20:51
【问题描述】:

我喜欢new emulation feature introduced in the new Chrome。事实上,我非常喜欢用它来测试移动网站的多种分辨率/设备。为此,我需要对仿真功能进行某种控制。

有什么方法可以控制wish device被仿真吗?

如果知道如何开始 OpenQA.Selenium.Chrome.ChromeDriver 模拟移动设备会很好。

提前致谢。

【问题讨论】:

标签: google-chrome selenium-webdriver webdriver google-chrome-devtools selenium-chromedriver


【解决方案1】:

您可以尝试向 Chrome 驱动程序添加选项。

ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3");

在上面的示例中,提供了“用户代理”开关。同样请尝试使用“window-size”命令行开关。

如果有效,请告诉我。

chrome 的所有命令行开关列表如下。

http://peter.sh/experiments/chromium-command-line-switches/

注意:通过安装下面给出的 Chrome 插件,您可以获得各种设备所需的用户代理设置。

https://chrome.google.com/webstore/detail/user-agent-switcher-for-c/djflhoibgkdhkhhcedjiklpkjnoahfmg

【讨论】:

    【解决方案2】:

    这是我在 C# 中的做法:

    IWebDriver driver;
            string setDevice = "Apple iPhone 6";
            var mobileEmulation = new Dictionary<string, string> { { "deviceName", setDevice } };
            var chromeOptions = new ChromeOptions();
            chromeOptions.AddAdditionalCapability( "mobileEmulation", mobileEmulation );
            driver = new ChromeDriver( chromeOptions );
            driver.Manage().Timeouts().SetPageLoadTimeout( TimeSpan.FromSeconds( 90 ) );
            driver.Manage().Timeouts().ImplicitlyWait( TimeSpan.FromSeconds( Convert.ToDouble( 30 ) ) );
            return driver;
    

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 2016-10-08
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      相关资源
      最近更新 更多