How to use selenium to drive Chrome browser and open mode for phone mode

Source: Internet
Author: User

As mobile device usage continues to increase, the testing of mobile pages becomes increasingly important.

For the Internet company m Station test, if not through the dedicated Appium and other mobile testing tools, whether there is a convenient way to do? The answer, of course, is yes.

Using Chrome driver and chrome and going to Chrome's toggle device mode mode, you'll be able to simulate the phone side, directly below the code.

public class Test{public static void Main (String args[]) {system.setproperty ("Webdriver.chrome.driver", "e:/software/ Automation software/chromedriver.exe "); map<string, string> mobileemulation = new hashmap<string, string> (); Mobileemulation.put ("DeviceName", " Google Nexus 5 "); map<string, object> chromeoptions = new hashmap<string, object> (); Chromeoptions.put ("MobileEmulation", mobileemulation);D esiredcapabilities capabilities = Desiredcapabilities.chrome (); Capabilities.setcapability ( Chromeoptions.capability, chromeoptions); Webdriver Driver = new Chromedriver (capabilities); Navigation navigation=driver.navigate (); Navigation.to ("https://m.baidu.com/"); String Title=driver.gettitle (); System.out.println ("title:" +title);}}

Speaking of the chrome version and the Chromedriver version I used, these two will have pits if they don't fit well.

Chrome version:

Chrome Driver:

Go to this place http://chromedriver.storage.googleapis.com/index.html do not open their own way, haha, download version 2.15 I am the Windows platform, download the 32 that, This way selenium every time the browser is mobile phone mode, you can operate on the mobile phone some tests.

How to use selenium to drive Chrome browser and open mode for phone mode

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.