Chrome Analog Mobile Browser Python+selenium

Source: Internet
Author: User

     near Time Test H5 page, use Chrome browser and then F12 switch to phone mode, just start using selenium frame and then simulate Operation F12, but found that switch to phone mode and then return to the original browser mode , later on a variety of Baidu, finally found the answer, the following is the sample code # -*- coding: utf-8 -*-from selenium import  Webdriverfrom time import sleepprotocol= ' http ' url=protocol+ '://m.baidu.com ' mobileEmulation  = {' devicename ':  ' iphone 6 '}options = webdriver. Chromeoptions () options.add_experimental_option (' mobileemulation ',  mobileemulation) driver =  Webdriver. Chrome (executable_path= ' Chromedriver.exe ',  chrome_options=options) driver.get (URL) class openh5 ():     def openbaidu (self):         #driver = self.driver        print  "Tap input Box"          driver.find_element_by_id ("index-kw"). Clear ()              DRIVER.FIND_ELEMENT_BY_ID ("Index-kW "). Send_keys (U" Test ")                  driver.find_element_by_id ("Index-bn"). Click ()         driver.get_ Screenshot_as_file (".. /.. /screen/chaweizhang.png ")         sleep (3)           #driver. Find_element_by_xpath (".//*[@id = ' app ']/div/div/div[3]/ul/li[3]/span[text () = ' Activity ']. Click ()         print u ' Close browser '                  driver.quit ()          login1 =openh5 () Login1.openbaidu () sleep (5)


Chrome Analog Mobile Browser Python+selenium

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.