First, if the chrome option has this analog device (such as iphone 6 Plus):
1, start selenium Grid first, such as command: Java-jar Selenium-server-standalone-xxx.jar.
2, the code is as follows:
#Coding=utf-8 fromSeleniumImportwebdrivermobile_emulation= {"devicename":"Apple IPhone 6 Plus"}chrome_options=Webdriver. Chromeoptions () chrome_options.add_experimental_option ("mobileemulation", mobile_emulation) driver= Webdriver. Remote (command_executor='Http://127.0.0.1:4444/wd/hub', Desired_capabilities= Chrome_options.to_capabilities ())
Second, if the chrome option is not pre-set the analog device, you can also configure yourself, the code is as follows:
#Coding=utf-8 fromSeleniumImportwebdrivermobile_emulation= { "Devicemetrics": {"width": 414,"Height": 736,"Pixelratio": 3.0 }, "useragent":"mozilla/5.0 (IPhone; CPU iPhone os 9_1 like Mac os X applewebkit/601.1.46 (khtml, like Gecko) version/9.0 mobile/13b143 safari/601.1"}chrome_options=Webdriver. Chromeoptions () chrome_options.add_experimental_option ("mobileemulation", mobile_emulation) driver= Webdriver. Chrome (chrome_options =chrome_options)
Selenium launch the Chrome simulator analog phone