Selenium open Google Chrome as a phone simulator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.