使用selenium和chromedriver将chrome移动模拟旋转到横向



在移动模拟中,有什么方法可以将chrome旋转到横向和向后?

我正在运行python 2.7铬67.0.3396.99

在stackoverflow上已经有一个非常古老的问题了,但chrome版本和chromedriver版本都发生了变化。

我想知道是否有任何方法可以旋转到景观与铬和硒铬驱动器的最后一次发布,因为我找不到正确的方法来做。

感谢

您可以通过在设备矩阵中设置高度和宽度来实现这一点:以下是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);
}

它将以横向模式打开浏览器
希望这能帮助你,也许你可以在Python代码中实现它:(

最新更新