zoukankan      html  css  js  c++  java
  • 浏览器模拟手机模式操作

    代码实现如下:

    import os
    from  selenium import webdriver
    
    #配置浏览器以手机模式启动
    chrome_options = webdriver.ChromeOptions()
    #选择一种存在的模式手机设备(分辨率)
    chrome_options.add_experimental_option('mobileEmulation',{'deviceName':'iPhone X'})
    print(type(chrome_options)) #import os
    from  selenium import webdriver
    
    #配置浏览器以手机模式启动
    chrome_options = webdriver.ChromeOptions()
    #选择一种存在的模式手机设备(分辨率)
    chrome_options.add_experimental_option('mobileEmulation',{'deviceName':'iPhone X'})
    print(type(chrome_options)) #<class 'selenium.webdriver.chrome.options.Options'>
    print(chrome_options.to_capabilities()) #{'browserName': 'chrome', 'version': '', 'platform': 'ANY', 'goog:chromeOptions': {'mobileEmulation': {'deviceName': 'iPhone X'}, 'extensions': [], 'args': []}}
    #将chrome_options:创建一个包含所有已设置选项和返回包含所有内容的词典
    new_new_chrome_options = chrome_options.to_capabilities()
    path= os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    executable_path = f'{path}/driver/chromedriver.exe'
    #创建一个driver
    driver = webdriver.Chrome(executable_path=executable_path,desired_capabilities=new_new_chrome_options)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('index-kw').send_keys('李白
    ')
    driver.quit()
    print(chrome_options.to_capabilities())
    #将chrome_options:创建一个包含所有已设置选项和返回包含所有内容的词典
    new_new_chrome_options = chrome_options.to_capabilities()
    path= os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    executable_path = f'{path}/driver/chromedriver.exe'
    #创建一个driver
    driver = webdriver.Chrome(executable_path=executable_path,desired_capabilities=new_new_chrome_options)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('index-kw').send_keys('李白
    ')
    driver.quit()
  • 相关阅读:
    foj 2111 Problem 2111 Min Number
    hdoj 1175 连连看
    poj 2377 Bad Cowtractors
    poj 3666 Making the Grade
    2018华南理工大学程序设计竞赛 H-对称与反对称
    hdoj 4293 Groups
    FOJ Problem 2273 Triangles
    poj 3411 Paid Roads
    Codeforces 235A. LCM Challenge
    离散对数二连 poj 2417 Discrete Logging & HDU 2815 Mod Tree
  • 原文地址:https://www.cnblogs.com/zhuxibo/p/14266540.html
Copyright © 2011-2022 走看看