1

there is any way to rotate chrome to landscape and back, while in mobile emulation ?

i'm running python 2.7 chrome 67.0.3396.99

there is already a very old question about this on stackoverflow, but the chrome version is changed and also the cromedriver version is changed.

I would like to know if there is any way to rotate to landscape with the last release of chrome and chromedriver with selenium, because i can't found a correct way to do it.

Thanks

ilmetu
  • 448
  • 11
  • 27

1 Answers1

0

You can do this by setting height and width in device matrices : Below is the code in java :

/** It gives chrome driver to run on chrome browser emulator
     * @return instance of chromedriver
     */
    public static WebDriver getChromeDriverForChromeEmulator() {
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver-2.35.exe");
        Map<String, Object> deviceMetrics = new HashMap<String, Object>();
        deviceMetrics.put("width", 1024);  // device width
        deviceMetrics.put("height", 768); // device height
        deviceMetrics.put("pixelRatio", 2.0);
        Map<String, Object> mobileEmulation = new HashMap<String, Object>();
        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 options = new ChromeOptions();
        options.setExperimentalOption("mobileEmulation", mobileEmulation);
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);

        return new ChromeDriver(capabilities);
    }

It will open the browser in landscape mode.
Hope that helps you and may be you can implement it in your Python Code :)

dangi13
  • 1,275
  • 1
  • 8
  • 11
  • 3
    Hi, i would like to open the browser in portrait and at some point rotate the browser , do you think it will be possible ? – ilmetu Jul 19 '18 at 06:16