Using Chrome driver and chrome and going to Chrome's toggle device mode mode, you can simulate the phone side very well, directly below the code
public class Runtest {Webdriver driver; @BeforeClass public void Beforeclass () {System.setproperty ("Webdriver.chrome.driver", "C:\Windows\System32\chrom Edriver.exe "); map<string, string> mobileemulation = new hashmap<string, string> (); Set up the device, for example: iphone x mobileemulation.put ("DeviceName", "iphone X"); Here is the name of the emulator to use, which is the top Model map<string in the emulator in the browser, object> chromeoptions = new hashmap<string, object> (); Chromeoptions.put ("Mobileemulation", mobileemulation); Desiredcapabilities capabilities = Desiredcapabilities.chrome (); Capabilities.setcapability (chromeoptions.capability, chromeoptions); try {driver = new chromedriver (capabilities); } catch (Exception e) {System.out.println (E.getmessage ()); }} @Test public void Run () {driver.get ("http://m.baidu.com/"); }
The name of the device, the name must be the same, or it will go wrong
Selenium open Google Chrome as a phone simulator