Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is an example of setting the device mode with height width and scalefactor with devtools and selenium4
package com.devtools;
import org.openqa.selenium.devtools.DevTools;
import java.util.HashMap;
import java.util.Map;
public class SetDeviceMode {
final static String PROJECT_PATH = System.getProperty("user.dir");
public static void main(String[] args){
System.setProperty("", PROJECT_PATH + "/src/main/resources/chromedriver");
ChromeDriver driver;
driver = new ChromeDriver();
DevTools devTools = driver.getDevTools();
Map deviceMetrics = new HashMap()
put("width", 600);
put("height", 1000);
put("mobile", true);
put("deviceScaleFactor", 50);
driver.executeCdpCommand("Emulation.setDeviceMetricsOverride", deviceMetrics);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment