Edit Chrome settings disguised as mobile M station

Source: Internet
Author: User

Change the properties of the PC-side Chrome browser and set the PC-side Chrome browser to a mobile-phone-size browser.

#!usr/bin/env python#-*-coding:utf-8-*-#edit chrome settings disguised as mobile m station fromSeleniumImportWebdriverImportUnittest,timeclassTestdemo (unittest. TestCase):defTest_ipadchrome (self): Options=Webdriver. Chromeoptions ()#--user-agent= ' xxxx ' to modify the HTTP request header's agent string to disguise the PC-side Chrome browser as a mobile browserOptions.add_argument ('--user-agent=mozilla/5.0 (IPad; CPU os 5_0 like Mac os X applewebkit/534.46 (khtml,like Gecko) version/5.1 mobile/9a334 safari/7534.48.3') Driver= Webdriver. Chrome (chrome_options=options) Driver.get ('http://www.baidu.com') Time.sleep (3) driver.find_element_by_id ('kw'). Send_keys ('IPad') Time.sleep (2)        #View Camouflage EffectsDriver.get ('about:version') Time.sleep (10) Driver.quit ()defTest_iphonechrome (self): Options=Webdriver. Chromeoptions () options.add_argument ('--user-agent=mozilla/5.0 (IPhone; CPU iPhone 5_0 like Mac OS X) applewebkit/534.46 (khtml,like Gecko) version/5.1 mobile/9a334 safari/7534.48. 3') Driver= Webdriver. Chrome (chrome_options=options) Driver.get ('http://www.baidu.com') Time.sleep (2) driver.find_element_by_id ('index-kw'). Send_keys ('IPhone') Time.sleep (2) Driver.get ('about:version') Time.sleep (10) Driver.quit ()defTest_android236chrome (self): Options=Webdriver. Chromeoptions () options.add_argument ('--user-agent=mozilla/5.0 (Linux; U        Android 2.3.6;en-us; Nexus S build/grk39f) applewebkit/533.1 (khtml,like Gecko) version/4.0 Mobile safari/533.1') Driver= Webdriver. Chrome (chrome_options=options) Driver.get ('http://www.baidu.com') Time.sleep (2) driver.find_element_by_id ('index-kw'). Send_keys ('Android 2.3.6') Time.sleep (2) Driver.get ('about:version') Time.sleep (10) Driver.quit ()defTest_android402chrome (self): Options=Webdriver. Chromeoptions () options.add_argument ('--user-agent=mozilla/5.0 (Linux; U        Android 4.0.2;en-us; Galaxy Nexus build/icl53f) applewebkit/534.30 (khtml,like Gecko) version/4.0 Mobile safari/534.30') Driver= Webdriver. Chrome (chrome_options=options) Driver.get ('http://www.baidu.com') Time.sleep (2) driver.find_element_by_id ('index-kw'). Send_keys ('Android 4.0.2') Time.sleep (2) Driver.get ('about:version') Time.sleep (10) Driver.quit ()if __name__=='__main__': Unittest.main ()

Edit Chrome settings disguised as mobile M station

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.